J. Dutch J. Dutch - 1 year ago 38
Swift Question

How do I get a string between slashes -Swift

I have string like so


Which needs to be translated into an Array of strings so that if I printed the array it would look like this
print(arrayOfStrings) // prints ["blah","hahaha","lalala"]

I am new to swift so forgive me if this question is foolish

Answer Source


let text = "/blah//hahaha//lalala/"

you can

let chunks = String(text.characters.dropFirst().dropLast()).componentsSeparatedByString("//")

and this is what you get

["blah", "hahaha", "lalala"]