Swift字符串格式化学习

let elem1 = 1

let elem2 = 2

let str = String(format:"%02d:%02d",elem1,elem2)

print(str)

let name = "zz"

let age = 11

let height = 1.22

let info = "my name is \(name),age is \(age),height is \(height)"

let urlString = "www.sss.com"

let header = (urlString as NSString).substring(to: 3)

let body = (urlString as NSString).substring(with: NSMakeRange(4, 3))

let footer = (urlString as NSString).substring(from: 8)

for c in urlString.characters {

print(c)

}

let str4 = "hello"

let str5 = "world"

let str6 = str4 + str5

你可能感兴趣的:(Swift字符串格式化学习)