my code is like the following:
let fileName = "/users/lezi/downloads/Zootopia.srt"
var srtFile = try? String(contentsOfFile: fileName)
let range = srtFile?.range(of: "00:00:59,825")
print(srtFile?[range!])
srtFile?.replaceSubrange(range!, with: "00:00:59,826")
print(srtFile?[range!])
I hope the "00:00:59,825" is replaced to "00:00:59,826", but the print is "Optional("\r\n\r\n2")\n", some characters just before "00:00:59,825"
print. Usingreplacingoccurenzces(of:with)seems to work though so it seems that this should be closed as a duplicaterange(of:)andreplaceSubrange()should work as well (and is not equivalent toreplacingOccurrences(of:with:)). I think it would be more helpful to figure out why the above code does not work as expected (instead of closing as a duplicate of a question about a different method).replaceSubrangefunction works fine, it is the secondprint(srtFile?[range])statement that doesn't work. If I print the whole file I can see the change. So I guess this then should be closed as "Can not reproduce"?