//: A UIKit based Playground for presenting user interface
import UIKit
//字符串索引
let greeting = "Guten Tag!"
greeting[greeting.startIndex]
greeting[greeting.index(before: greeting.endIndex)]
greeting[greeting.index(after: greeting.startIndex)]
let index = greeting.index(greeting.startIndex,offsetBy: 7)
greeting[index]
//插入
var welcome = "Hello"
welcome.insert("!", at: welcome.endIndex)
welcome.insert(contentsOf:"there",at: welcome.index(before: welcome.endIndex))
//删除
welcome.remove(at: welcome.index(before: welcome.endIndex))
let range = welcome.index(welcome.endIndex, offsetBy: -6)..<welcome.endIndex
welcome.removeSubrange(range)
swift 字符串索引 删除字符串 插入字符串
点赞
收藏