Photo by AltumCode / Unsplash

String: Inserting and Removing

Swift Apr 3, 2022

String'e indekse göre ekleme ve silme işlemine örnek bir kullanım.

Inserting

var welcome = "hello"
welcome.insert("!", at: welcome.endIndex)
// welcome now equals "hello!"

welcome.insert(contentsOf: " there", at: welcome.index(before: welcome.endIndex))
// welcome now equals "hello there!"

Removing

welcome.remove(at: welcome.index(before: welcome.endIndex))
// welcome now equals "hello there"

let range = welcome.index(welcome.endIndex, offsetBy: -6)..<welcome.endIndex
welcome.removeSubrange(range)
// welcome now equals "hello"

Tags

Furkan Ozoglu

iOS Developer & Geomatics Engineer