从电话簿中提取的联系号码中删除空格 [英] Remove white space from contact number fetched from phone book

查看:129
本文介绍了从电话簿中提取的联系号码中删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个非常基本的问题,但我现在陷入困境。

I know its a very basic question, but I am stuck at this point.

我从电话簿中取出联系电话号码并将它们放在一个阵列中。

I am fetching contact numbers from phonebook and having them in an array.

然后从NSString中的数组中取一个特定的一个

And then fetching a particular one from array in NSString

我试图从数字中删除空格,但实际上并没有下面的代码:

And I am trying to remove white space from the number, but it is not actually with the below written codes:

NSString *num = @"+44 123 456 7890";

num = [num stringByReplacingOccurrencesOfString:@" " withString:@"0"];

**OR**

num = [num stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

请告诉我要删除此空间需要做什么。

Please let me know what I need to do to remove this space.

谢谢

编辑

NSString *num = [contactNumbers objectAtIndex:i];
        num = [num stringByReplacingOccurrencesOfString:@"-" withString:@""];
        num = [num stringByReplacingOccurrencesOfString:@" " withString:@""];
        num = [num substringFromIndex:[num length]-10];


推荐答案

完成诀窍:

NSString * strippedNumber = [num stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [number length])];

这篇关于从电话簿中提取的联系号码中删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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