I'm trying to replace a substring with another substring but I'm getting this error:
cannot convert value of type 'String.Index' (aka 'String.CharacterView.Index') to expected argument type 'Range<String.Index>' (aka 'Range<String.CharacterView.Index>')
Here is my Code:
// This are the position of the substrings:
let rangeOne = strToSort.index(strToSort.startIndex, offsetBy: (i-1))
let rangeTwo = strToSort.index(strToSort.startIndex, offsetBy: (i))
Here is where I try to make the replacement:
strToSort = strToSort.replacingCharacters(in: rangeOne, with: strToSort.substring(with: rangeTwo))
But I'm getting this error:
Any of you knows what I'm doing wrong or a work around this?
I'll really appreciate your help
EHLLOAGAIN
toHELLOAGAIN
? – Nirav Dvar chars = "EHLLOAGAIN".characters.map{String($0)}
swap(&chars[0], &chars[1])
– Leo Dabus