Groups | Blog | Home
all groups > dotnet general > september 2003 >

dotnet general : Comparing strings


Robert Jacobson
9/2/2003 2:00:35 PM
I think what you're looking for (basically) is the Levenshtein edit-distance
algorithm. This algorithm takes two strings as an input. It then counts
the number of corrections (insertions, deletions or substitution of
individual characters) that are necessary to make the strings the same.

For example, with the inputs "Hello World" and "Hllo Woorld," it will return
"2" since there are two corrections necessary: insert an "e" in the first
word, and delete an "o" in the second word.

This isn't built into the .Net framework, so you'll have to build your own.
Try a Google search on "edit distance algorithm." There's an explanation of
the algorithm here, with some VB6 code:

http://www.merriampark.com/ld.htm



[quoted text, click to view]

Chad Myers
9/2/2003 4:03:14 PM
[quoted text, click to view]

I think he means something like DIFFERENCE or
SOUNDEX in SQL Server.

Unfortunately there's nothing like this built into
..NET and it's not a simple algorithm, but I'm sure
you could probably find some examples on some
academic pages. I think it has something to do
with phonetic analysis of the words and then
comparing the likeness of the placement of the
various phonetic parts relative to the other
string. MSR might have something like this
already, they are always suprising me with
new projects.

-c

Dennieku
9/2/2003 8:28:26 PM
Does anybody have an idea how to compare two strings?
What I want to know is the percentage of the differences between the strings

Thx,
Dennieku

Jon Skeet
9/2/2003 9:46:16 PM
[quoted text, click to view]

Could you define exactly what you mean by "percentage of the
differences"? If you can define it *exactly*, that will probably
suggest a way of calculating it simply.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet/
Jon Davis
9/3/2003 7:17:51 PM
I did a search .. you might find something useful in here...

http://dotnet.jku.at/applications/Diff/Src.aspx

Jon


[quoted text, click to view]

AddThis Social Bookmark Button