Last active
November 8, 2017 15:54
-
-
Save NickAger/13b31868e16f37233c6f6be440e9629f to your computer and use it in GitHub Desktop.
Understanding Swifts substringToIndex & substringFromIndex
This file contains 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
"hello".substringToIndex(1) // "h" | |
// s.substringToIndex(1) // String may not be indexed with 'Int', it has variable size elements | |
s.substringToIndex(s.startIndex.advancedBy(1)) // "h" | |
s.substringFromIndex(s.startIndex.advancedBy(1)) // "ello" | |
s.substringFromIndex(s.endIndex.advancedBy(-1)) // "o" | |
s.substringToIndex(s.endIndex.advancedBy(-1)) // "hell" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment