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"]

相关文章:

  • 2021-06-13
  • 2022-12-23
  • 2021-11-22
  • 2022-01-12
  • 2021-04-22
  • 2021-07-30
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2021-12-10
  • 2022-02-11
相关资源
相似解决方案