is there anyway to use `when` with ignorecase when...
# announcements
m
is there anyway to use
when
with ignorecase when it comes to comparing strings
d
t
How about converting to either uppercase or lowercase in
when
?
Copy code
when (text.toUpperCase()) {
   "FOO" -> doFoo()
   "BAR" -> doBar()
}
d
That produces an intermediary string though.
m
yeah, but I think we need to do that for both strings
t
If your scenario is performance-critical, you may prefer @diesieben07's answer as it does not allocate strings. In any other case, choose whichever you find the most readable.
d
Depends on the number of cases. It's pretty much switch (+allocation) vs if else.