Answer by cactustictacs for starts with inside switch statement Kotlin
You can't really do this and avoid the repetition, because when you provide an argument in when (something) the something is an expression that produces a value, which is fixed before the matching...
View ArticleAnswer by sirjoga for starts with inside switch statement Kotlin
This is really interesting question.Maybe something like that, lol?run { operator fun String.unaryPlus() = "This is some message".startsWith(this) when {+"This" -> { println("Starts with This")...
View ArticleAnswer by paspielka for starts with inside switch statement Kotlin
I found an answer on how to do it without tons of repetition.you can do it like this:val str = "!settings change something"val args = str.split(" ")when (args[0]) {"!settings" -> TODO()"!other"...
View ArticleAnswer by deHaar for starts with inside switch statement Kotlin
You can use a when without an argument:val msg = "This is some message"when { msg.startsWith("This") -> println("Starts with This") msg.startsWith("That") -> println("Starts with That") else...
View Articlestarts with inside switch statement Kotlin
when(message) { .startsWith("hey")}How do I check if my string starts with a certain word inside a switch statement in Kotlin?
View Article