I
I
Ivan Vorobei2019-02-27 10:07:38
Swift
Ivan Vorobei, 2019-02-27 10:07:38

How to split a string with an array of words?

There is a text (string).
There is an array of words (also string).
You need to split the text into an array of strings. The delimiter is each word in the array. There is a function to split by a string:
components(separatedBy:)
But I didn’t find an array

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iMaximus, 2019-02-27
@iMaximus

Hey! This is izi.

extension String {
    var getWordsArray: [String] {
        return components(separatedBy: .punctuationCharacters)
            .joined()
            .components(separatedBy: .whitespaces)
    }
}
"Превед, как дела".getWordsArray

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question