CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2001
    Posts
    33

    How to compare 2 similar strings?

    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 !!!



  2. #2
    Join Date
    Aug 1999
    Posts
    28

    Re: How to compare 2 similar strings?

    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.


  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: How to compare 2 similar strings?

    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
    Iouri Boutchkine
    iouri@hotsheet.NOSPAM.com

  4. #4

    Re: How to compare 2 similar strings?

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured