I copied mobile number from contact . I got it like \"8008708600\\u{e2}\" . I wish to remove \\u{e2} from string. String is copied with exponent character
I made a function for help:
public func formatContactsPhoneNumber(number: String) -> String {
var buffer = ""
for (i, char) in number.unicodeScalars.enumerated() {
guard CharacterSet.decimalDigits.contains(char) else {
continue
}
buffer.append(number[i])
}
return buffer
}
It's work well for me.
I have used following Code:
var str = "8008708600\u{e2}"
str = str.replacingOccurrences(of: "\u{e2}", with: "")
print(str)
Output:
Hope this helps.
Code:
var number = self.yourTextField.text
self.yourTextField.text = ""
let onlyDigits: CharacterSet = CharacterSet.decimalDigits.inverted
let greeting = number!
number = ""
for aa in 0..<greeting.count {
let index = greeting.index(greeting.startIndex, offsetBy: aa)
let bb = String(describing: greeting[index])
if bb.rangeOfCharacter(from: onlyDigits) == nil {
number = "\(String(describing: number!))\(greeting[index])"
}
}
self.yourTextField.text = number!