在objective-c中拆分电话号码

时间:2013-04-14 15:51:52

标签: objective-c phone-number

我需要分辨电话号码,格式为05XXXXXXXX 并放在“ - ”之间 05X-XXXXXXX 我只需要在区号和号码之间加上“ - ”符号

我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

如果您确定需要将-始终放在第4位,您可以这样做

NSString *yourPhoneString=@"05XXXXXXXX";
NSMutableString *phoneNumber = [NSMutableString stringWithString:yourPhoneString];
[phoneNumber insertString:@"-" atIndex:3];

答案 1 :(得分:0)

感谢Anoop

This is the answer NSString *yourPhoneString=@"05XXXXXXXX";
NSMutableString *phoneNumber = [NSMutableString stringWithString:yourPhoneString];
[phoneNumber insertString:@"-" atIndex:3];