I'm trying to replace the just first character of a string. Using this answer, I'm able to replace all current characters with the one I want, but what I really need is to only replace the character if it's at the start of a word.
For example, replace c with t:
Original String: Jack is cool
New Sting: Jack is tool
My Current Code:
let aString: String = "jack is cool"
let toArray: Array = aString.componentsSeparatedByString(" ")
let newString: String = aString.stringByReplacingOccurrencesOfString("c", withString: "t", options: NSStringCompareOptions.LiteralSearch, range: nil)
This would print out as:
"jatk is tool"
I assume I have to do something with the range attribute in the newString.