String.Index is the font for String.CharacterView.Index . The index itself cannot be increased. Rather, you can use the index(after:) instance method in CharacterView , which you used to retrieve the index.
For instance.:
let str = "foobar" let chars = str.characters if let bIndex = chars.index(of: "b") { let nextIndex = chars.index(after: bIndex) print(str[bIndex...nextIndex])
Or, if you have an index (e.g. str.startIndex ), you can use the index(_:, offsetBy:) instance method index(_:, offsetBy:) , also available directly for String instances:
let str = "foobar" let startIndex = str.startIndex let nextIndex = str.index(startIndex, offsetBy: 1) print(str[startIndex...nextIndex]) // fo
source share