Skip to content

Instantly share code, notes, and snippets.

@makthrow
Created February 24, 2016 00:42
Show Gist options
  • Save makthrow/a1593ad53b9e10ab1e4c to your computer and use it in GitHub Desktop.
Save makthrow/a1593ad53b9e10ab1e4c to your computer and use it in GitHub Desktop.
import Foundation
var s = "hello"
s.startIndex // starts at 0
let index = s.startIndex.advancedBy(2) // index is a String.index to the 3rd glyph, "l"
print (index)
s.insertContentsOf("abc".characters, at: index)
let startIndexPlusOne = s.startIndex.advancedBy(1) // advance s.startIndex from 0 to 1
let endIndex = s.startIndex.advancedBy(6) // advance s.startIndex from 0 to 6
let substring = s[index..<endIndex] // "abcl"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment