Swift中的String

来源:互联网 发布:多核优化软件 编辑:程序博客网 时间:2024/05/16 06:27


let name : String = "YYY"


for c inname.characters {

    print(c)

}


//字符串拼接

let str1 = "我的名字"

let str2 = "小明"

let str3 = str1 + str2


//字符串拼接基本数据类型

let name = "小明"

let age = 18

let height = 170

let info = "我的名字叫\(name),我的年龄是\(age),我的身高是\(height)cm"


//字符串冯世华

let n = 2

let s = 8

let time1 = String.init(format:"%02d:%02d", arguments: [n,s])


//字符串方法截取

let string = "www.baidu.com"

let head = (stringas NSString).substring(to: 3)

let middle = (stringas NSString).substring(from: 10)

let bottom = (stringas NSString).substring(with:NSMakeRange(4, 5))

















0 0