我有这样的字符串"/blah//hahaha//lalala/"
需要将其转换为字符串数组,以便在打印数组时看起来像print(arrayOfStrings) // prints ["blah","hahaha","lalala"]
如果这个问题是愚蠢的话,我是新手,请原谅我
答案 0 :(得分:7)
let text = "/blah//hahaha//lalala/"
let chunks = String(text.characters.dropFirst().dropLast()).componentsSeparatedByString("//")
["blah", "hahaha", "lalala"]
答案 1 :(得分:2)
还有网址解决方案
let string = "/blah//hahaha//lalala/"
let components = NSURL(fileURLWithPath: string).pathComponents!.dropFirst()
print(components)