Results 1 to 5 of 5

Thread: [RESOLVED] Ignoring Case in String Comparison

  1. #1

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943

    [RESOLVED] Ignoring Case in String Comparison

    It's been a long time since I've done any coding, and I feel like an idiot for having to ask this and not being able to just figure it out but I'm being kind of lazy and I promised work that I'd have this report run for them. Is there a simple way to ignore case in a string, or is there a simple way to convert a string to all lowercase? The method I've thought of is splitting the string into a variant, going through the variant and figuring out of the ASCII code for each letter was cap or lowercase, making it all lowercase, and then re-assembling the string but this will add significant time to the time it will take me to run this report as I'm comparing a list of about 300 names to a list of about 6000 names and would need to do this for each one in addition to some other code that ultimately writes several values for each name on a spreadsheet.

    Any help would be appreciated
    Last edited by Skitchen8; May 4th, 2008 at 09:15 AM.
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Ignoring Case in String Comparison

    You can use LCase$() or UCase$() to convert a String to lower/upper case. Also, you can use 'Option Compare Text' in Module's Declaration level. E.g.:
    Code:
    Option Explicit
    Option Compare Text 'ignores case
    
    Private Sub Form_Load()
      Dim x As String
      Dim y As String
      
      x = "Visual Basic"
      y = "visual basic"
      
      Debug.Print LCase$(x) = y
      Debug.Print x = y 'only returns True if 'Option Compare Text' is used
    End Sub

  3. #3

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Ignoring Case in String Comparison

    The best way:
    vb Code:
    1. Option Compare Text

    At the top of your form/module/class if you are not doing any binary compares...
    Last edited by randem; May 3rd, 2008 at 06:05 PM.

  5. #5

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943

    Re: Ignoring Case in String Comparison

    Thanks a lot guys, the help is greatly appreciated
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

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