473,508 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Consequtive letter matches...please help

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.

Jul 5 '06 #1
2 1374
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.

--
Terry
"al*****@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.

Jul 5 '06 #2
al*****@altavista.com wrote:
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
Now, do you mean the same "order", or the same actual characters, in the
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.
Jul 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
6006
by: Alan J. Flavell | last post by:
OK, today's email brought a comment from a reader, pointing out something that I'd long since noticed myself but hadn't done anything about it. On my pages, I've got a first-letter style on...
14
12316
by: Mr.Clean | last post by:
I have a string. I'd like to take this string and make each char change until it gets to another char at the same position of the string. Example: Original String: " NEW YORK " Final...
2
1600
by: JLeonard | last post by:
I would like to save my Access form letters as a txt file who's file name matches the value in a 'last name' field. One file for each record. Any ideas for how I might do this? Thanks in...
2
3355
by: Colin Halliday | last post by:
I have a Word 2003 mail merge main document (form letter) that is linked to another Word document data source for the mail merge. If I open this doc using the Word GUI, it first asks me to...
0
236
by: almurph | last post by:
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...
3
17774
by: =?Utf-8?B?cGFucGF3ZWw=?= | last post by:
Is there a way to quickly determine if the key pressed was from 'A'-'Z' or '0'-'9' range? I really don't like to write switch with every Keys.A, Keys.B, etc key listed Paul
5
4528
by: RolfK | last post by:
Dear ALL, I'm writing some first examples to get a better understanding of XSLT/ XPATH2.0. Please excute this code, any xml input is OK. I'm using saxon. The example runs perfect with ALTOVA,...
3
2517
by: Smokey Grindel | last post by:
Alright so I have a string... that can be anything like this then have a number like 102.34m, yes there is a m behind it to say "this is money", no I didn't design the spec thats just how data...
2
4385
by: bozo789 | last post by:
Hi Forum, First let me begin by stating I am a student and have read the proper posting procedure concerning students. I am a begginer learning with the Miracle C Work Bench. I know my code is...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.