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.
Swift String remove() The remove() method removes a character in the string at the specified position.
The dropFirst() method removes the first character of the string.
To remove the last character from a string we need to use the removeLast() method in swift.
var str = "\\dagdahughuad\\dajughdaug"
var str2 = str.stringByReplacingOccurrencesOfString("\\", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
print(str2)
This will output
dagdahughuaddajughdaug
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With