Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a string between slashes -Swift

Tags:

string

ios

swift

I have string like so "/blah//hahaha//lalala/"

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

like image 769
J. Dutch Avatar asked Apr 27 '26 09:04

J. Dutch


1 Answers

Given

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

you can

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

and this is what you get

["blah", "hahaha", "lalala"]
like image 86
Luca Angeletti Avatar answered Apr 29 '26 00:04

Luca Angeletti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!