我有以下代码:
let refreshedToken = FIRInstanceID.instanceID().token()
var encriptat3: String = "ope=sql¶=UPDATE xw_usuarios SET IDFIREBASE = '" + refreshedToken! + "' where USUARIO = '" + self.usuari + "'"
encriptat3 = encriptat3.stringByReplacingOccurrencesOfString("\\", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
我的字符串的最终值是:
"ope=sql¶=UPDATE xw_usuarios SET IDFIREBASE = \'XXXXXXX\' where USUARIO = \'99997\'"
我的问题是:如何删除" \"从我的结束价值和正确建立我的网址?
目前我正在使用Swift 2.3。感谢。
答案 0 :(得分:3)
swift 3
let string1 = "ios\\programmer"
let string2 = string1.replacingOccurrences(of: "\\", with: "")
print("string2 --%@",string2);
答案 1 :(得分:1)
let aString = "ope=sql¶=UPDATE xw_usuarios SET IDFIREBASE = \'XXXXXXX\' where USUARIO = \'99997\'"
let newString = aString.replacingOccurrences(of: "\\", with: "")
修改强>
您使用的是哪个版本的Xcode?你导入Fondation了吗?
let aString = "ope=sql¶=UPDATE xw_usuarios SET IDFIREBASE = \'XXXXXXX\' where USUARIO = \'99997\'"
let newString = (string as NSString).stringByReplacingOccurrencesOfString("\\", withString: "")
答案 2 :(得分:0)
var val =你的字符串
val = val.replacingOccurrences(of:“你的替换字符串在这里(比如\,)”,用:“”)
这对我来说很有用