Results 1 to 6 of 6

Thread: String Comparrison Question??

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    33

    Question

    Hi

    I am trying to write a function that works with files that only have a ".txt" extension.

    code:

    str1 = '(Whatever the filename is)
    str2 = "*.txt"

    intCompare1 = str1 Like str2
    if intCompare1 = "-1" then
    msgbox("Contains txt file")
    else
    msgbox("Does not contain txt file")
    end if

    Question: How do I include in the comparrison, variations of .txt? (eg. *.txt, *.TXT, *.Txt etc...)

    Thanks

    Gregg

  2. #2
    Guest
    Why not just convert it to lowercase? Whether it's uppercase or lowercase, it's still the same file.

    Code:
    str1 = LCase$("C:\FILE.TXT")
    str2 = ".txt"
    
    If Instr(str1, str2) Then
    Msgbox ("Contains txt file")
    Else
    Msgbox ("Does not contain txt file")
    End If

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Convert both to lower case and the test will always be true


    Code:
    intCompare1 = lcase(str1) like lcase(str2)

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    33
    Thanks for your help guys.
    Much appreciated...

    Gregg

  5. #5
    Guest
    Gen-X, two great minds think alike .

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    YOu could just put option compare text, in the declarations instead of using lcase$
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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