Skip to content

Instantly share code, notes, and snippets.

@alexpaul
Created November 2, 2018 21:45
Show Gist options
  • Save alexpaul/d9bca650c5ebc876100ea041ac649b8a to your computer and use it in GitHub Desktop.
Save alexpaul/d9bca650c5ebc876100ea041ac649b8a to your computer and use it in GitHub Desktop.
Working with String.Index
// working with String index
let str = "The Swift Programming Language"
// accessing the first character
print("the first character is \(str[str.startIndex])")
// accessing the last character
print("the last character is \(str[str.index(before: str.endIndex)])")
// access range of characters
let ninthCharacterIndex = str.index(str.startIndex, offsetBy: 8)
print("range of characters \(str[str.startIndex...ninthCharacterIndex])")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment