var str = "Hello Swift"
// Insert "," between Hello and Swift
str.insert(",", at: str.index(str.startIndex, offsetBy: 5))
// Insert "God Damn" between Hello, and Swift
if let insertIndex = str.firstIndex(of: "S") {
str.insert(contentsOf: "God Damn ", at: insertIndex)
}
// 여기에 있는 firstIndex(of: "S") 메소드는 처음으로 나오는 S 문자를 찾아 그 앞에 문자를 넣는것이다도시.
print(str) // ==============================> "Hello, God Damn Swift"
'ios Development > Swift' 카테고리의 다른 글
structure & class (0) | 2020.01.17 |
---|---|
String Editing 2 문자 바꾸기, 삭제하기 (0) | 2020.01.13 |
Substring (0) | 2020.01.12 |
까먹지 말자 String interpolation (0) | 2020.01.09 |
String interpolation (0) | 2020.01.09 |