In Kotlin, you can split a string by comma using the split
function.
In this example,
str
with a value containing commas.split
function to split the string into an array of substrings using comma as the delimiter.fun main() {
val str = "apple,banana,orange"
val substrings = str.split(",")
for (sub in substrings) {
println(sub)
}
}
apple banana orange
In this tutorial, we learned How to Split a String by Comma in Kotlin language with well detailed examples.