arrays - 字符串中的双引号(转义字符)(格式 : ) in swift

标签 arrays swift string

\不在 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/

相关文章:

javascript - Vue.js 导入对象

ios - 无法在静态表格 View 之上显示事件指示器

php - 如何在不在php中插入每个循环的情况下将数组插入数据库

python - pickle numpy 数组或列表时 pickle 文件大小

ios - 为什么我的 UIAlertController 没有被解雇?

php - 在 PHP 中有从多字节字符串中获取字符的简单方法吗?

字符串或字符串常量

mysql - 在字符串中查找精确匹配的正则表达式可以在其他地方使用,但不能在 MySql 查询上使用

c++ - std::array<> 是否只保证在堆栈上分配?

ios - 源文件中的 Swift 编辑器占位符