Created
March 11, 2016 23:01
-
-
Save ryantxr/86331040318743dc8a97 to your computer and use it in GitHub Desktop.
Get substring for a string by searching for a character
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
// Given the string "Fox is in the hole", how to get a substring up to the first space. | |
let myMessage = "Fox is in the hole" | |
var result: String? | |
if let index = myMessage.characters.indexOf(" ") { | |
result = myMessage.substringToIndex(index) | |
} | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment