ios 在Swift中从字符串中删除“\”(反斜杠)

egdjgwm8  于 2023-02-10  发布在  iOS
关注(0)|答案(4)|浏览(415)

下面的代码:

let refreshedToken = FIRInstanceID.instanceID().token()

var encriptat3: String = "ope=sql&para=UPDATE xw_usuarios SET IDFIREBASE = '" + refreshedToken! + "' where USUARIO = '" + self.usuari + "'"
encriptat3 = encriptat3.stringByReplacingOccurrencesOfString("\\", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)

字符串的最终值是:

"ope=sql&para=UPDATE xw_usuarios SET IDFIREBASE = \'XXXXXXX\' where USUARIO = \'99997\'"

我的要求是:我怎样才能从我的结束值中删除""并正确地构建我的网址?
我现在用的是Swift 2.3谢谢。

tag5nh1u

tag5nh1u1#

雨燕3号

let string1 = "ios\\programmer"
let string2 = string1.replacingOccurrences(of: "\\", with: "")
print("string2 --%@",string2);
roqulrg3

roqulrg32#

Swift 5.7+:

let value = "Some \\value with \\backslashes."
value.replacing("\\", with: "") // Some value with backslashes.
np8igboo

np8igboo3#

let aString = "ope=sql&para=UPDATE xw_usuarios SET IDFIREBASE = \'XXXXXXX\' where USUARIO = \'99997\'"
let newString = aString.replacingOccurrences(of: "\\", with: "")
    • 编辑:**

你用的是哪个版本的Xcode?你导入了Fondation吗?

let aString = "ope=sql&para=UPDATE xw_usuarios SET IDFIREBASE = \'XXXXXXX\' where USUARIO = \'99997\'"

let newString = (string as NSString).stringByReplacingOccurrencesOfString("\\", withString: "")
bvuwiixz

bvuwiixz4#

var val = your string

val = val.replacingOccurrences(of: "your replace string here(like \,)", with: "")

相关问题