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