Swift分割字符串


var str_componets = "I Like Swift "

str_componets.componentsSeparatedByString(" ")

這樣,str_componets分成了四部分:

["I", "Like", "Swift", ""]

 

也可以用NSCharacterSet進行分割:

var str_componets = "I would prefer a face-to-face talk with my friends"

str_componets.componentsSeparatedByCharactersInSet(NSCharacterSet(charactersInString: " -"))

這樣,str_componets分成了:

["I", "would", "prefer", "a", "face", "to", "face", "talk", "with", "my", "friends"]


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM