我对字符串中的反斜杠有疑问。
当我用这段代码创建一个字符串时:
let url = webProtocol + siteHost + "/tables/coupon?$expand=source&$filter=Source/Name eq '" + category + "'&" + siteApi
我期待这个网址
https://swoup.azurewebsites.net/tables/coupon?$expand=source&$filter=Source/Name eq 'Recommended'&ZUMO-API-VERSION=2.0.0
但是我明白了
https://swoup.azurewebsites.net/tables/coupon?$expand=source&$filter=Source/Name eq \'Recommended\'&?ZUMO-API-VERSION=2.0.0
我尝试使用
删除它们stringByReplacingOccurrencesOfString("\\", withString: "")
但这并没有帮助。我还尝试在 ' 之前添加反斜杠,但没有帮助。
最佳答案
根据你的问题还不清楚,但我相信反斜杠实际上不在字符串中,而是由 XCode 打印出来的。例如,在 playground 中输入以下内容:
let siteApi="test=123"
let category="Category1"
let webProtocol="https://"
let siteHost="www.testme.com"
let url = webProtocol + siteHost + "/tables/coupon?$expand=source&$filter=Source/Name eq '" + category + "'&" + siteApi
print( url)
你会看到输出不包含反斜杠。
https://www.testme.com/tables/coupon?$expand=source&$filter=Source/Name eq 'Category1'&test=123
关于ios - 如何从字符串swift中删除\(反斜杠),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39233023/