Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to compare two strings and measure the percentage they match Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Aug-02
Category
Object Pascal-Strings
Language
Delphi All Versions
Views
93
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

Does anyone know how or does anyone know of a good procedure to match two strings? 
What I want is a % match between two strings. Something like Hart and Harts are 80% 
equal.

Answer:

1   uses
2     math;
3   
4   function IsStrMatch(s1, s2: string): Double;
5   var
6     i, iMin, iMax, iSameCount: Integer;
7   begin
8     iMax := Max(Length(s1), Length(s2));
9     iMin := Min(Length(s1), Length(s2));
10    iSameCount := -1;
11    for i := 0 to iMax do
12    begin
13      if i > iMin then
14        break;
15      if s1[i] = s2[i] then
16        Inc(iSameCount)
17      else
18        break;
19    end;
20    if iSameCount > 0 then
21      Result := (iSameCount / iMax) * 100
22    else
23      Result := 0.00;
24  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC