I know we can write if, else if, else if
with a ignore case.
if (someString.equals("otherString", ignoreCase = true)) {
}
I am very curious about this, how to write a when(in Java it is a switch) condition with ignoring the case.
There are a couple of options:
Translate strings to lower (or upper) case:
when (someString.toLowerCase()) {
"otherString1".toLowerCase() -> { /*...*/ }
"otherString2".toLowerCase() -> { /*...*/ }
}
Directly use equals
method:
when {
someString.equals("otherString1", ignoreCase = true) -> { /*...*/ }
someString.equals("otherString2", ignoreCase = true) -> { /*...*/ }
}