0

I have a string line from EditText, all words separated from each other by comma just like this:

"Some, string, words, bla-bla"

And I need to create array from this string, each element would be separate:

"Some", "string", "words", "bla-bla"

So, I saw how it was done on Java here but idk how convert it to kotlin, as I know Kotlin doesn't have split operator

This array I will save in preferences by putStringSet and use in another activity

2
  • 1
    ...Kotlin does have split Commented Jan 15, 2021 at 21:35
  • can you help me how to use it in my case? Commented Jan 15, 2021 at 21:36

1 Answer 1

0

Kotlin has a split function too. It will return a List<String>. If you you need an array in the end, call toTypedArray():

val strArray: Array<String> = "Some, string, words, bla-bla".split(", ").toTypedArray()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.