iOS 7联系号码空格不是空格 [英] iOS 7 contact number spaces are not spaces

查看:154
本文介绍了iOS 7联系号码空格不是空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在尝试检索联系人号码列表并尝试对其进行操作。我意识到每当我添加新联系人(更新到iOS 7之后)后,新的联系人格式都会发生变化,因为新添加的数字中存在间距。

In my app I am trying to retrieve the list of contact's number and try to do operations on them. I realized that whenever I have added new contacts (after updating to iOS 7) the new contacts formatting has changed, as there are spacings in the newly added numbers.

使用普通的替换方法不会删除空格。

Using the ordinary replace methods does not remove the spaces.

这些真的是空格还是这些空格?我的目标是取回'空格'免费电话号码。

Are these really spaces or what are these ? my objective is to get back the 'space' free number.

例如,如果号码是 1 818 323 323 323 ,我想得到 1818323323323

for example, if the number is 1 818 323 323 323, I want to get 1818323323323

推荐答案

我看了看这不是摆脱'空间'而是留下十进制字符。这段代码为我做了这个:

I looked at this as not getting rid of 'spaces' but being left with only decimal characters. This code did that for me:

phoneNumberString = [[phoneNumberString componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""];

这取出一切,这不是数字0-9。

This takes out everything that's not a number 0-9.

Swift 4.1:

phoneNumberString = phoneNumberString.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")

这篇关于iOS 7联系号码空格不是空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆