How to replace string into string in Swift?
You can use stringByReplacingOccurrencesOfString
, e.g.
let s1 : String = "Red small car"
let s2 = s1.stringByReplacingOccurrencesOfString("small", withString: "big")
You can try using stringByReplacingOccurrencesOfString
let string = "Big red car"
let replaced = (string as NSString).stringByReplacingOccurrencesOfString("Big", withString: "Small")
Edit In Swift 5
import Foundation
let string = "Big red car"
let replaced = string.replacingOccurrences(of: "Big", with: "Small")