473,659 Members | 2,540 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Consequtive letter matches...pleas e 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 1402
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*****@altavi sta.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*****@altavis ta.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
6022
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 paragraphs. So far, so good: some of the paragraphs begin with a link, and there are styles in the stylesheet for link, hover etc. The first letter is still displayed as styled for the paragraph's first-letter.
14
12337
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 String: "SAN FRANSISCO" I'd like each char to loop through the chars on a timer
2
1609
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 advance! -- JL
2
3372
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 confirm that I want to run a query to select the data from the data source file, then it opens the form letter fine. I can preview the merged records and complete a merge to a new document. I have a VB 2006 project (.net framework 2.0) which opens the...
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 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
3
17821
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
4534
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, but fails with SAXON. Please refere to line with element <matcheswhich is quite close to the error.
3
2524
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 comes in... well I had a regex that replaces all those m's in a string where there is a number before it with no m... so its just the string with 102.34... well this worked fine until we got negative money! so now when its -102.34m it still has the...
2
4391
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 probably doing everything the long way, and there are more proficient ways to write my program, but like I said, I am just learning this foreign language. I'll get there!! (smiling) Here is my problem, In my code I am trying to both verify that a...
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7360
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
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 we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.