remove \\u{e2} characters from string

前端 未结 3 1909
滥情空心
滥情空心 2021-01-15 21:25

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

相关标签:
3条回答
  • 2021-01-15 21:36

    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.

    0 讨论(0)
  • 2021-01-15 21:47

    I have used following Code:

     var str = "8008708600\u{e2}"
     str = str.replacingOccurrences(of: "\u{e2}", with: "")
     print(str)
    

    Output:

    Hope this helps.

    0 讨论(0)
  • 2021-01-15 21:53

    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!
    
    0 讨论(0)
提交回复
热议问题