1字符串类型的初始化
let str = String(format:"hello %@", arguments:["word"])
print(str)
2 Int 类型的初始化
let number = 1
let str = String(format: "第%d行", arguments: [number]) // 第一行
let str = String(format: "第%03d行", arguments: [number]) // 第001行
print(str)
3 Double 类型
let number = 2.22222
let str = String(format: "第%fkg", arguments: [number]) //2kg
let str1 = String(format: "第%.0fkg", arguments: [number]) //2kg
let str1 = String(format: "第%.1fkg", arguments: [number]) //2.2kg
网友评论