Home replacingOccurrences not working on Device
Reply: 0

replacingOccurrences not working on Device

user1297
1#
user1297 Published in June 21, 2018, 4:38 am

I made a trimming whitespace code to remove whitespace in the textfield input, but here is a problem, on the emulator it works fine and removes whitespace but on the device, it won't work at all here is my code:

var number = numberTxtField.text
if number!.hasPrefix("+98") {
    let start = number!.index(number!.startIndex, offsetBy: 0);
    let end = number!.index(number!.startIndex, offsetBy: 3);
    number!.replaceSubrange(start..<end, with: "0")
    self.trimmed = number!.replacingOccurrences(of: " ", with: "")
    print(self.trimmed)
    let pattern = "^[0-9]+$"
    let predicate = NSPredicate(format: "self MATCHES [c] %@", pattern)
    if predicate.evaluate(with: self.trimmed) {
        print("Valid")
        if self.trimmed == nil && self.trimmed == "" {
            return
        }
        numberTxtField.resignFirstResponder()
        self.view.endEditing(true)
        SendNumber()
    }
}

When I type +98 912 123 1234 on the emulator it returns 09121231234 and when I do it on my device it returns 0 912 123 1234.

Does anyone know why?

this is my result on my device (iPhone 6s with ios 11.2.5):

this is my result on the emulator (iPhone 8 iOS 11.2):

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304533 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO