Last active
September 22, 2017 02:46
-
-
Save jianghaoyuan2007/ab5804101f9298e4f318d7da71f025b2 to your computer and use it in GitHub Desktop.
The example for getting substring of string with a range in Swift 4.
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
import Foundation | |
var greeting = "Hello, Swift 4." | |
let startIndexOffsetBy = 7 | |
let endIndexOffsetBy = -1 | |
let startIndex = greeting.index(greeting.startIndex, offsetBy: startIndexOffsetBy) | |
let endIndex = greeting.index(greeting.endIndex, offsetBy: endIndexOffsetBy) | |
let rangeOfSubstring = [startIndex...endIndex] | |
let substring = String(greeting[startIndex...endIndex]) | |
print(substring) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment