Results 1 to 2 of 2

Thread: Comparing strings (same length)

  1. #1

    Thread Starter
    Frenzied Member Devion's Avatar
    Join Date
    Sep 2000
    Location
    The Netherlands
    Posts
    1,049

    Question

    How can I compare 2 strings with a fixed length?

    string #1 is "bla bla bla"
    string #2 is "bla bla bla\bla"
    ^.........^ <- needs to be checked and should be ok.

    string #1 is "bla bla blaa"
    string #2 is "bla bla bla\bla"
    ^..........^ <- should be wrong.. duh

    I need to check if string 2 is indentical to string 1 with the length of string 1.

    (does this make sense?)

    Thanks in advance.



  2. #2
    Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    53
    How about:

    Dim s1 As String
    Dim s2 As String
    Dim r As Boolean

    s1 = "bla bla bla"
    s2 = "bla bla bla\bla"

    r = (StrComp(Left$(s2, Len(s1)), s1) = 0)
    Debug.Print r

    s1 = "bla bla blaa"
    s2 = "bla bla bla\bla"
    r = (StrComp(Left$(s2, Len(s2)), s1) = 0)
    Debug.Print r

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