473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Comparing strings

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
5 3371
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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: beliavsky | last post by:
By mistake I coded something like print ("1" > 1) and got the result "True". Comparing an integer and a string seems meaningless to me, and I would prefer to have an exception thrown. Can...
26
by: William Park | last post by:
How do you compare 2 strings, and determine how much they are "close" to each other? Eg. aqwerty qwertyb are similar to each other, except for first/last char. But, how do I quantify that? ...
5
by: Curtis Gilchrist | last post by:
I am required to read in records from a file and store them in descending order by an customer number, which is a c-style string of length 5. I am storing these records in a linked list. My...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
6
by: BrianJones | last post by:
I have a problem with the int strcmp(str1,str2) function: When I do: char *pass; char *passv; pass = getpass("Please enter....."); passv = getpass("Please verify.....");
88
by: William Krick | last post by:
I'm currently evaluating two implementations of a case insensitive string comparison function to replace the non-ANSI stricmp(). Both of the implementations below seem to work fine but I'm...
2
by: Manny Chohan | last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30 AM. How can i compare dates .net c# or if there is any other way such as Javascript. Thanks Manny
15
by: luc.saffre | last post by:
Hello, here is something that surprises me. #coding: iso-8859-1 s1=u"Frau Müller machte große Augen" s2="Frau Müller machte große Augen" if s1 == s2: pass
1
by: Jetboy555 | last post by:
Sample input: 2000 Georgia Tech 30 Virginia 20 1999 Virginia 20 Virginia tech My Problem is in taking the input in correctly. I take the year in correctly, but i'm having trouble with the...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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,...
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...

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.