473,466 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Create 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 1365
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
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
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
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
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
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
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
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
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.