「Kotlin」splitで複数の区切り文字を指定するサンプル

2021年7月13日

書式
文字列.split(“:",",")
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fun main() {
val cft = "123:key1,456:key2,789:key3,090:key4"
//コロン、カンマをカンマで区切る
val resArr = cft.split(":",",")
for (u in resArr) {
print(u +" ")
}
println()
}
fun main() { val cft = "123:key1,456:key2,789:key3,090:key4" //コロン、カンマをカンマで区切る val resArr = cft.split(":",",") for (u in resArr) { print(u +" ") } println() }
fun main() {

    val cft = "123:key1,456:key2,789:key3,090:key4"
      //コロン、カンマをカンマで区切る
    val resArr = cft.split(":",",")
    for (u in resArr) {
        print(u +" ") 
    }
      println()
}

実行結果
>kotlin arkgame.jar
123 key1 456 key2 789 key3 090 key4

Kotlin

Posted by arkgame