Select Case is Case-Insensitive

  1. 3 weeks ago

    Julia T

    Feb 5 Sandy Hook, Connecticut

    I'm pretty surprised after all these years to discover that

    Select Case s
    Case "A"
      return "Capital"
    Case "a"
      Return "Lower"
    end Select

    returns "Capital" for s = "a". Does anyone else consider this a bug? Not to mention ironic...

    select case 0
    case s.Compare( "A", ComparisonOptions.CaseSensitive )
      return "Capital"
    case s.Compare( "a", ComparisonOptions.CaseSensitive )
      return "Lower"
    end select

    If that helps.

  2. Norman P

    Feb 5 Pre-Release Testers, Xojo Pro outside listening to the crick...
    Edited 3 weeks ago

    just like every other string comparison in Xojo is

    if "a" = "A" then
      break
    end if
  3. Julia T

    Feb 5 Sandy Hook, Connecticut
    Edited 3 weeks ago

    @Norman P just like every other string comparison in Xojo is

    Amazing that I've never realized this in all my coding... or maybe knew once and forgot.

  4. Kem T

    Feb 5 Pre-Release Testers, Xojo Pro, XDC Speakers, MVP Answer Connecticut
    select case 0
    case s.Compare( "A", ComparisonOptions.CaseSensitive )
      return "Capital"
    case s.Compare( "a", ComparisonOptions.CaseSensitive )
      return "Lower"
    end select

    If that helps.

  5. Norman P

    Feb 5 Pre-Release Testers, Xojo Pro outside listening to the crick...

    If this is basically a String extension method that relies on the same code as strcomp then you can still have issues since case sensitive is a byte wise comparison and wont handle composed vs decomposed unicode

    text, however, does

  6. Julia T

    Feb 5 Sandy Hook, Connecticut

    @Norman P If this is basically a String extension method that relies on the same code as strcomp then you can still have issues since case sensitive is a byte wise comparison and wont handle composed vs decomposed unicode

    text, however, does

    Byte-wise would suit me fine, I don't go for that newfangled unicode stuff :)

  7. Norman P

    Feb 5 Pre-Release Testers, Xojo Pro outside listening to the crick...
    Edited 3 weeks ago

    a quick test suggest the extension method is doing the right thing when comparing two strings that are "the same utf-8 character" - one composed and one decomposed

    so its not JUST byte wise

    &ue4 is lower case ä made up of a single code point
    &u61 + &u308 is the decompoased version of that (lower case a + combining diaresis)

    both appear as ä
    but they are different bytes

    yet this code considers then "equal" - you do not hit the break point

    Dim s1 As String = &ue4
    Dim s2 As String = &u61 + &u308
    
    If s1.Compare(s2, ComparisonOptions.CaseSensitive) <> 0 Then
      Break
    End If

    if you change &uE4 for &UC4 you get the capitalized version of Ä and it DOES hit the break point - as you should expect

or Sign Up to reply!