Created
November 2, 2018 21:45
-
-
Save alexpaul/d9bca650c5ebc876100ea041ac649b8a to your computer and use it in GitHub Desktop.
Working with String.Index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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