|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Consequtive letter matches...please helpHope you can help me. This is a trick one - at least I think so. I have 2 strings. I have to calculate the "score" of the strings. Score is determined by matching patterns of letters within the strings. Essentially it is the sum of the consequtive letter matches. Here are the rules of score: 1. Start at the end of the shorter string and and add up the amount of letters found in the same order in the longer string. Continue for all letters in the shorter string 2. I think that you may have to work from the end of the longer string also 3. If strings are equal - pick either, note that the answer should be the same regardless of which strings is compared against which. As you can see the maximum value of score could be the length of the shortest string (in this case the shorter string is identical to the longer, like a subset) Simple Worked Example: String1: "My name is John" String2: "My name is Johnson" Score = 12 (for "name isJohn") + 3 (for "My") = 15 Can anyone help me with coding this algorithm please? Comments/sample-code greatly appreciated. Is this a well known string matching algorithm? Thank you, Al. I am not sure that I understand the rule. You say it is "add up the amount of
letters found in the same order in the longer string. Continue for all letters in the shorter string", but that is not what you do in your example. There the score is the length of the largest substring (in the shorter of the 2 comparison strings) found in the other string. In either case, it is not a difficult algorithm to program. Think of using a couple of nested For loops and using the InStr function. -- Show quoteHide quoteTerry "almu***@altavista.com" wrote: > Hi, > > Hope you can help me. This is a trick one - at least I think > so. I > have 2 strings. I have to calculate the "score" of the strings. Score > is determined by matching patterns of letters within the strings. > Essentially it is the sum of the consequtive letter matches. > > > Here are the rules of score: > > > 1. Start at the end of the shorter string and and add up the amount of > letters found in the same order in the longer string. Continue for all > letters in the shorter string > 2. I think that you may have to work from the end of the longer string > also > 3. If strings are equal - pick either, note that the answer should be > the same regardless of which strings is compared against which. > > > As you can see the maximum value of score could be the length > of the > shortest string (in this case the shorter string is identical to the > longer, like a subset) > > > Simple Worked Example: > > > String1: "My name is John" > String2: "My name is Johnson" > > > Score = 12 (for "name isJohn") + 3 (for "My") = 15 > > > Can anyone help me with coding this algorithm please? > Comments/sample-code greatly appreciated. Is this a well known string > matching algorithm? > > > Thank you, > Al. > > almu***@altavista.com wrote:
> 1. Start at the end of the shorter string and and add up Now, do you mean the same "order", or the same actual characters, in the > the amount of letters found in the same order in the longer string. > Continue for all letters in the shorter string same position that they appear in the original string? To do the latter, you'd have something like Function Score( _ ByVal s1 as String _ , ByVal s2 as String _ ) as Integer Dim iSub as Integer For iSub = 1 To Len( s1 ) If Mid$( s1, 1 ) <> " " Then If Mid$( s1, 1 ) <> Mid$( s2, 1 ) Then Score = ( iSub - 1 ) Exit Function End If End If Next Score = Len( Replace( s1, " ", "" ) ) End Function The above will count the matching /letters/, ignoring spaces. > Is this a well known string matching algorithm? I've never come across it before... ;-)HTH, Phill W.
TreeView control checked based on if records exist
What exactly does it mean when they say CopyFile() and Progress Bar? Get object from name how to parse an Enum Structure in vb.net CreateInstance and late binding what is best practice to populate large combobox? VB 2005 Newbie - Binding? No of files in folder activate a click onto a picture button |
|||||||||||||||||||||||