问题
I have string which contains few \
and I want to remove all of them. can anyone tell me how can I do that. I have already tried stringByReplacingOccurrencesOfString
but it's not working out for me.
回答1:
var str = "\\dagdahughuad\\dajughdaug"
var str2 = str.stringByReplacingOccurrencesOfString("\\", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
print(str2)
This will output
dagdahughuaddajughdaug
回答2:
Converted above code in to SWIFT 3
var str = "\\dagdahughuad\\dajughdaug"
var str2 = str.replacingOccurrences(of: "\\", with: "", options:
NSString.CompareOptions.literal, range: nil)
print(str2)
来源:https://stackoverflow.com/questions/30183162/swift-remove-character-from-string