Quantcast
Channel: starts with inside switch statement Kotlin - Stack Overflow
Browsing latest articles
Browse All 5 View Live

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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article

starts 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

Browsing latest articles
Browse All 5 View Live