var variableString = "Horse"
variableString += " and carriage"
append()
在为字符串添加字符(Character)
let exclamationMark: Character = "!"
variableString.append(exclamationMark)
let multiplier = 3
let message = "(multiplier) times 2.5 is (Double(multiplier) * 2.5)"
characters
属性 ,用于获取字符串中的字符
let varString:String = "Jaesun is 25"
for char in varString.characters {
print(char)
}
let greeting = "Guten Tag!"
// starindex 起始下标 endIndex 结尾下标
greeting[greeting.startIndex]
// 某下标之前的下标 如:! 的下标
greeting.index(before: greeting.endIndex)
// 某下标之后的下标: 如 u 的下标
greeting[greeting.index(after: greeting.startIndex)]
// 从某下标开始向后偏移后的下标 如:a的下标
let index = greeting.index(greeting.startIndex, offsetBy: 7)