且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

替换出现的 "\:"

更新时间:2022-05-14 08:48:03

您需要使用另一个反斜杠来转义反斜杠.所以如果你想用 "\:" 替换 ":" 你需要用 "\\:" 替换.

You need to escape backslashes with another backslash. So if you want to replace ":" with "\:"you need to replace with "\\:".

let backslashString = string.replacingOccurrences(of: ":", with: "\\:")