\不在 String(format:) 内部用于转义字符。
如何在 swift 中将双引号(转义字符)放入字符串(格式:)中?
例子
let timeString = String(format: "https://stackoverflow.com/character=\"inside\"")
我需要在 String(format:) 中传递不带双引号的 url 参数,所以我需要转义里面的双引号
我得到 stackoverflow.com/character="inside"我需要 stackoverflow.com/character=inside
我输入引号作为
字符串(格式:'https://stackoverflow.com/character=“里面”')
但是在传递给 url 时我应该不带引号传递它
字符串(格式:'https://stackoverflow.com/character=inside
因为在 url 中它显示为
https://stackoverflow.com/character= “里面”
最佳答案
只是做:
let timeString = String(format: "https://stackoverflow.com/character=\"inside\"").replacingOccurrences(of: "\"", with: "")
这将输出为:
https://stackoverflow.com/character=inside
将出现的 "替换为空。
编码愉快!
关于arrays - 字符串中的双引号(转义字符)(格式 : ) in swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54235525/