By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,650 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,650 IT Pros & Developers. It's quick & easy.

Comparing strings

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Dennieku <de******@hotmail.com> wrote:
Does anybody have an idea how to compare two strings?
What I want to know is the percentage of the differences
between the strings


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #2

P: n/a
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

"Dennieku" <de******@hotmail.com> wrote in message
news:K3*********************@amsnews02.chello.com. ..
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

Jul 19 '05 #3

P: n/a
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Dennieku <de******@hotmail.com> wrote:
Does anybody have an idea how to compare two strings?
What I want to know is the percentage of the differences
between the strings


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.


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
Jul 19 '05 #4

P: n/a
Robert Jacobson <rj**********************@nospam.com> wrote:
I just noticed your cross-post to .dotnet.languages.csharp -- the VB example
probably isn't what you're looking for. <g> That link also has examples in
Java and C++ that would be easy to translate to C#.


In particular, I'd be more than happy to translate it from Java to C#,
if this is indeed the algorithm required.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #5

P: n/a
I did a search .. you might find something useful in here...

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

Jon
"Chad Myers" <cm****@N0.SP.AM.austin.rr.com> wrote in message
news:ut*************@TK2MSFTNGP10.phx.gbl...
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Dennieku <de******@hotmail.com> wrote:
Does anybody have an idea how to compare two strings?
What I want to know is the percentage of the differences
between the strings


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.


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

Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.