Results 1 to 6 of 6

Thread: How can I copare two strings

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Germany
    Posts
    15

    Question

    I have two variables one includes Data form the registry and in the other I have put Data from a file.
    And Now I would like to compare these two variables.
    Have anyone a good idear with I can to this.

    Variable one:
    Home;Test;Room

    Variable one:
    Home;Test;Room

    In advance the cordial owing to.



  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Code:
    If Variable1 = Variable2 Then
        MsgBox "The Variables are the same!"
    Else
        MsGBox "They Differ!"
    End If
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    Member
    Join Date
    Aug 2000
    Posts
    32

    Smile

    You could use InStr it would just tell you if string1 is in string2.

    InStr(1, string1, string2, 1)

    or

    if (string1 = string2) then
    'do something
    end if

    HTH

    Phil

    VB 6, SQL, Java, AutoLISP, Avenue and on a good day AML

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Originally posted by Jop
    Code:
    If Variable1 = Variable2 Then
        MsgBox "The Variables are the same!"
    Else
        MsGBox "They Differ!"
    End If
    This does a case-sensitive comparison. This means, "abc" is different from "ABC".
    If you want it case-insensitive ("abc"="ABC"="aBc", etc.) then at the very very very top of the code (first line of the code window), add this line.
    Code:
    Option Compare Text
    Alrighty?

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    StrComp Function Example
    
    This example uses the StrComp function to return the results of a string comparison. 
    If the third argument is 1, a textual comparison is performed. If the third argument is 0 or omitted, a binary comparison is performed.
    
    Dim MyStr1, MyStr2, MyComp
    
    MyStr1 = "ABCD"
    MyStr2 = "abcd" 
       
    MyComp = StrComp(MyStr1, MyStr2, 1)   ' Returns 0.
    MyComp = StrComp(MyStr1, MyStr2, 0)   ' Returns -1.
    MyComp = StrComp(MyStr2, MyStr1)   ' Returns 1.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    If you want to use case-insesitive compare you could also do:

    Code:
    If lcase(String1) = lcase(String2) Then
    MsgBox "SAME!"
    Else
    MsgBox "Different!"
    End If
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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