Last active
November 25, 2020 07:43
-
-
Save wiwi-git/1f934800615cf962259713310cc3553f to your computer and use it in GitHub Desktop.
Swift String.range에 대해
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
let text = "가나다라마바사아자차" | |
func stringParsing(text:String) -> (String,String,String)? { | |
let index0 = text.startIndex | |
let indexE = text.endIndex | |
let result = text[index0 ..< indexE] | |
print(result) | |
guard text.contains("다라") else { return nil } | |
if let range0 = text.range(of: "다라") { | |
let startWord = text[range0].startIndex | |
let endWord = text[range0].endIndex | |
let w0 = text[text.startIndex ..< startWord] | |
let w1 = text[startWord ..< endWord] | |
let w2 = text[endWord ..< text.endIndex] | |
return (String(w0),String(w1),String(w2)) | |
} else { | |
return nil | |
} | |
} | |
if let word = stringParsing(text: text) { | |
print("\(word.0)\n\(word.1)\n\(word.2)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment