I'm using a UITextView
to add some values into an array.
I'd like to separate the text from the UITextView
into single items if they have a newline (\n
) or a comma (,
) between them.
var values = self.textLabel.text.componentsSeparatedByString("\n")
for item in values {
if item != "" {
cellDataSet.insert([item, false], atIndex: 0)
}
}
If you want to separate a String
on multiple tokens, use componentsSeparatedByCharactersInSet(_:)
Example:
let text = "This is, some, text; With multiple | seperators"
let separators = NSCharacterSet(charactersInString: ",;|")
let values = text.componentsSeparatedByCharactersInSet(separators)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加