Select Case is Case-Insensitive

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…

just like every other string comparison in Xojo is

if "a" = "A" then
  break
end if

[quote=474335:@Norman Palardy]just like every other string comparison in Xojo is
[/quote]
Amazing that I’ve never realized this in all my coding… or maybe knew once and forgot.

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

If that helps.

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

[quote=474338:@Norman Palardy]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[/quote]
Byte-wise would suit me fine, I don’t go for that newfangled unicode stuff :slight_smile:

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