let greeting = "Guten Tag!"
greeting[greeting.startIndex]
// G
greeting[greeting.index(before: greeting.endIndex)]
// !
greeting[greeting.index(after: greeting.startIndex)]
// u
let index = greeting.index(greeting.startIndex, offsetBy: 7)
greeting[index]
indices
for index in greeting.characters.indices {
print("\(greeting[index]) ", terminator: "")
}
// 打印输出 "G u t e n T a g ! "
移除的范围
welcome.removeSubrange(welcome.startIndex...welcome.index(welcome.startIndex, offsetBy: 2))
前缀和后缀
通过调用字符串的hasPrefix(_:)/hasSuffix(_:)