Click to See Complete Forum and Search --> : How to compare 2 similar strings?


Blue Sky
March 28th, 2001, 09:24 PM
Suppose s1 = "S02K"
s2 = "S02KKKK"

How to check that these 2 strings are similar ?

I have used "like" to check them, but it won't work !!!

RGregoire
March 28th, 2001, 10:20 PM
Dim Pos As Integer

Pos = InStr(1,s2,s1)

If s1 is found in s2 then Pos will equal something other than 0. If s1 is not found in s2 then Pos will return 0.

Iouri
March 29th, 2001, 07:26 AM
PGregoire's solution will only let you know if s1 is a part of s2. If you want to compare that 2 strings are alike

If StrComp(s1, s2, vbTextCompare) = 0 Then
Call MsgBox("strings are the same")
Else
Call MsgBox("strings are different")
End If


Iouri Boutchkine
iouri@hotsheet.com

Daniel Andersson
March 30th, 2001, 11:20 AM
A perfectly correct answer, although a little C influenced. When we are using VB we could simply check:
If s1 = s2 then
MsgBox "Strings are the same"
else
MsgBox "Strings are different"
End If



-----------------------
Daniel Andersson