Swift中的String


let name : String = "YYY"


for c in name.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 = (string as NSString).substring(to: 3)

let middle = (string as NSString).substring(from: 10)

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

















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值