Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 14th, 2006, 11:53 PM
baseballdude_'s Avatar
baseballdude_ baseballdude_ is offline
Expert Learner
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2005
Location: Wisconsin
Posts: 1,879 baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)  Folding Points: 22104 Folding Title: Starter FolderFolding Points: 22104 Folding Title: Starter Folder
Time spent in forums: 1 Week 5 Days 12 h 1 m
Reputation Power: 62
Send a message via AIM to baseballdude_ Send a message via MSN to baseballdude_ Send a message via Yahoo to baseballdude_ Send a message via Google Talk to baseballdude_
String Comparison Percent

I adapted this from a post by Rich, but improved it and made it work for ASP using VBScript.

You call the function and it returns the percent (given as a decimal) that the two strings are alike.

ASP Code:
Original - ASP Code
  1. Dim arrLetters1
  2. Dim arrLetters2
  3.  
  4. Function CompareString(String1, String2)
  5.     Dim intLength1
  6.     Dim intLength2
  7.     Dim x
  8.     Dim dblResult
  9.  
  10.  
  11.     If UCase(String1) = UCase(String2) Then
  12.         dblResult = 1
  13.     Else
  14.         intLength1 = Len(String1)
  15.         intLength2 = Len(String2)
  16.  
  17.  
  18.         If intLength1 = 0 Or intLength2 = 0 Then
  19.             dblResult = 0
  20.         Else
  21.             ReDim arrLetters1(intLength1 - 1)
  22.             ReDim arrLetters2(intLength2 - 1)
  23.  
  24.             For x = LBound(arrLetters1) To UBound(arrLetters1)
  25.                 arrLetters1(x) = Asc(UCase(Mid(String1, x + 1, 1)))
  26.             Next
  27.  
  28.             For x = LBound(arrLetters2) To UBound(arrLetters2)
  29.                 arrLetters2(x) = Asc(UCase(Mid(String2, x + 1, 1)))
  30.             Next
  31.  
  32.             dblResult = SubSim(1, intLength1, 1, intLength2) / (intLength1 + intLength2) * 2
  33.         End If
  34.     End If
  35.  
  36.     CompareString = dblResult
  37. End Function
  38.  
  39.  
  40. Function SubSim(intStart1, intEnd1, intStart2, intEnd2)
  41.     Dim y
  42.     Dim z
  43.     Dim ns1
  44.     Dim ns2
  45.     Dim i
  46.     Dim intMax
  47.  
  48.     If (intStart1 > intEnd1) Or (intStart2 > intEnd2) Or (intStart1 <= 0) Or (intStart2 <= 0) Then
  49.         Exit Function
  50.     End If
  51.  
  52.     For y = intStart1 To intEnd1
  53.         For z = intStart1 To intEnd2
  54.             i = 0
  55.  
  56.             Do Until arrLetters1(y - 1 + i) <> arrLetters2(z - 1 + i)
  57.                 i = i + 1
  58.  
  59.                 If i > intMax Then
  60.                     ns1 = y
  61.                     ns2 = z
  62.                     intMax = i
  63.                 End If
  64.  
  65.                 If ((y + i) > intEnd1) Or ((z + i) > intEnd2) Then
  66.                     Exit Do
  67.                 End If
  68.             Loop
  69.         Next
  70.     Next
  71.  
  72.     intMax = intMax + SubSim(ns1 + intMax, intEnd1, ns2 + intMax, intEnd2)
  73.     intMax = intMax + SubSim(intStart1, ns1 - 1, intStart2, ns2 - 1)
  74.  
  75.     SubSim = intMax
  76. End Function

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > String Comparison Percent


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT