| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Smart String Comparison
Code:
Private b1() As Byte
Private b2() As Byte
Public Function Simil(String1 As String, String2 As String) As Double
Dim l1 As Long
Dim l2 As Long
Dim l As Long
Dim r As Double
If UCase(String1) = UCase(String2) Then
r = 1
Else
l1 = Len(String1)
l2 = Len(String2)
If l1 = 0 Or l2 = 0 Then
r = 0
Else
ReDim b1(1 To l1): ReDim b2(1 To l2)
For l = 1 To l1
b1(l) = Asc(UCase(Mid(String1, l, 1)))
Next
For l = 1 To l2
b2(l) = Asc(UCase(Mid(String2, l, 1)))
Next
r = SubSim(1, l1, 1, l2) / (l1 + l2) * 2
End If
End If
Simil = r
Erase b1
Erase b2
End Function
Private Function SubSim(st1 As Long, end1 As Long, st2 As Long, end2 As Long) As Long
Dim c1 As Long
Dim c2 As Long
Dim ns1 As Long
Dim ns2 As Long
Dim i As Long
Dim max As Long
If st1 > end1 Or st2 > end2 Or st1 <= 0 Or st2 <= 0 Then Exit Function
For c1 = st1 To end1
For c2 = st2 To end2
i = 0
Do Until b1(c1 + i) <> b2(c2 + i)
i = i + 1
If i > max Then
ns1 = c1
ns2 = c2
max = i
End If
If c1 + i > end1 Or c2 + i > end2 Then Exit Do
Loop
Next
Next
max = max + SubSim(ns1 + max, end1, ns2 + max, end2)
max = max + SubSim(st1, ns1 - 1, st2, ns2 - 1)
SubSim = max
End Function
Last edited by Shadow Wizard : January 1st, 2006 at 03:09 AM. Reason: added code tags to make the code more readable :) |
|
#2
|
|||
|
|||
|
Who wrote this?
It might be nice to credit the author of this code. I originally posted it to Planet Source Code back in 2000.
Atul Brad Buono |
|
#3
|
||||
|
||||
|
Quote:
Hello Atul, When I posted this code, it was taken from another thread in this forum. Ive taken a look at the URL provided, and the code does indeed appear to be yours originally. Feel free to post your information here, as credit is rightfully yours. Or I can include it within the original post. Send me a PM or shoot me an email at rich at developershed.com, and I'll hook you up. Rich |
|
#4
|
||||
|
||||
|
Ehh...shouldn't and Administrator know to post using [code][/code] tags?
__________________
www.xoise.com - www.ourfreegames.com - www.playtouchgames.com - www.randomtools.net - www.xenocide-rpg.com |
|
#5
|
||||
|
||||
|
Quote:
![]() |
|
#6
|
||||
|
||||
|
Ahh, lol...didn't see the date. Sorry :\
|
|
#7
|
||||
|
||||
|
And that dude just signed up to complain a year later.
![]()
__________________
................... ASCII and ye shall receive .................. Knowledge is the only resource on earth that multiplies when shared Support the Shemzilla Project Powered by C# |
|
#8
|
||||
|
||||
|
That's what I was wondering. It also seemed ironic that this "Rich" that I rarely ever see just happened to notice that 5 minutes after the guy posted complaining about it.
It's obviously not a deal in any way, just seems incredibly ironic. |
|
#9
|
||||
|
||||
|
Yes it does indeed.
He probably suscribed to the thread, and received the email as soon as someone posted a reply to the post ![]() |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Smart String Comparison |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|