use the soundex function of sqlserver, if you use that database...
Main Topics
Browse All TopicsI would like to match strings so that if a specific percentage is matched then consider it a complete match.
like
"welcome to expcrt exchange.com"
The string to find is "expert" (total 6 characters). it should match 5 characters which would be almost 84.2% match
Problems are:
1- string functions cannot be used as it need exact match for given string in the source string.
2- Using loops on source and target strings.. it need to track back references .. if consecutive characters are matched otherwise purge the found number of characters and start ahead of the index where it found 1 matching char.
Is there any such algorithm that allows such kind of comparisons?
-thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I played around with this a little, and the best method that I came up with was to write my own function to analyze the strings. I actually Wrote a function that incorporates three tests as separate functions.
Test1 compares the length of the two strings to see if they are very close to the same size.
Test2 compares the strings letter by letter from front to back and rates them based on matching letters.
Test3 Compares the strings letter by letter from back to front (In reverse of the other one)
Then I take all of the results, average them, and compare this result to my predefined tolerance level. If the result is more that the tolerance setting, it returns true, if not it returns false.
Here is the code... in my form I had two text fields, a button and a label. btnTest is the button... txtString1 as the first text box... txtString2 as the 2nd text box... and lblResult as the label...
Public Class frmMain
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
lblResult.Text = CStr(compareStrings(txtSri
End Sub
Private Function compareStrings(ByVal str1 As String, ByVal str2 As String, ByVal tolerance As Decimal) As Boolean
Dim decTest1 As Decimal = test1(str1, str2, 1)
Dim dectest2 As Decimal = test2(str1, str2)
Dim decTest3 As Decimal = test3(str1, str2)
Dim decAverage As Decimal = ((decTest1 + dectest2 + decTest3) / 3)
If decAverage >= tolerance Then
Return True
Else
Return False
End If
End Function
Private Function test1(ByVal string1 As String, ByVal string2 As String, ByVal tolerance As Integer) As Decimal
Dim int1 As Integer = string1.Length
Dim int2 As Integer = string2.Length
Dim intDifference As Integer = int1 - int2
intDifference = Math.Abs(intDifference)
Select Case intDifference
Case 0
Return 100D
Case Is > 0
'determine how much each character is worth, and subract that much for each
'character that you are off
Return (100 / string1.Length) * (string1.Length - intDifference)
End Select
End Function
Private Function test2(ByVal string1 As String, ByVal string2 As String) As Decimal
Dim I As Integer
Dim chardiff As Integer
chardiff = string1.Length - string2.Length
Dim Charval As Decimal
Select Case chardiff
Case Is < 0
'string2 is longer than string1
Charval = 100 / string2.Length
Case 0
'The two strings are equal
Charval = 100 / string1.Length
Case Is > 0
'string1 is longer than string2
Charval = 100 / string1.Length
End Select
Dim totalVal As Decimal = 0
If chardiff >= 0 Then
For I = 0 To string1.Length - 1
If string1.Chars(I) = string2.Chars(I) Then
totalVal += Charval
End If
Next
Else
For I = 0 To string2.Length - 1
If string1.Chars(I) = string2.Chars(I) Then
totalVal += Charval
End If
Next
End If
Return totalVal
End Function
Private Function test3(ByVal string1 As String, ByVal string2 As String) As Decimal
Dim I As Integer
Dim chardiff As Integer
chardiff = string1.Length - string2.Length
Dim Charval As Decimal
Select Case chardiff
Case Is < 0
'string2 is longer than string1
Charval = 100 / string2.Length
Case 0
'The two strings are equal
Charval = 100 / string1.Length
Case Is > 0
'string1 is longer than string2
Charval = 100 / string1.Length
End Select
Dim totalVal As Decimal = 0
If chardiff >= 0 Then
For I = string1.Length - 1 To 0 Step -1
If string1.Chars(I) = string2.Chars(I - chardiff) Then
totalVal += Charval
End If
Next
Else
For I = string2.Length - 1 To 0 Step -1
If string1.Chars(I) = string2.Chars(I) Then
totalVal += Charval
End If
Next
End If
Return totalVal
End Function
End Class
If you want to test this out in your application, you can copy the three functions into your app... compareStrings, test1, test2, and test3... and then call comparestrings with the proper parameters where you want to compare strings. In CompareStrings the first argument is the string you are trying to match... the second argument is the string you are testing as a possible match, and the third argument ... the tolerance setting ... is a decimal representative of the percentage match you are desiring... I would recommend 80... this will basically match every pair if there is only one letter off... usually even if a letter has been added... you can play around with that setting to make the match more strict or more lenient.
I hope this is a help.
Business Accounts
Answer for Membership
by: billprewPosted on 2009-09-16 at 04:07:17ID: 25344130
You might want to take a look at this posting.
e.com/Prog ramming/La nguages/ Vi sual_Basic /VB_DB/Q_2 2800605.ht ml
http://www.experts-exchang
~bp