码迷,mamicode.com
首页 > 编程语言 > 详细

Swift 操作字符串

时间:2015-02-15 12:03:12      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

 

字符串分隔:

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

swift语言的数组提供了一个map函数很好用! 
  可建立一个a数组的映射数组b,即数学上的 y = f(x) 

func fx(x : Int){ 
   reurn x + 10 
}    
var a = [1, 2, 3, 4, 5] 
var b = a.map(fx) 
println(b) 
   
  // [11, 12, 13, 14, 15]

 

Swift 操作字符串

标签:

原文地址:http://www.cnblogs.com/ericjun/p/4292569.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!