LoginSignup
0
1

More than 1 year has passed since last update.

Kotlinのwhen式で正規表現を使う

Last updated at Posted at 2022-08-03

以外とすぐ見つけられなかったので備忘のため

val testWord = "Kotlin is good!"
when {
    Regex(""".*Kotlin.*""").matches(testWord) -> "Contains Kotlin"
    Regex(""".*Scala.*""").matches(testWord)  -> "Contains Scala"
    testWord == "Java"                        -> "Java!"
    else                                      -> "no word"
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1