【代码笔记】将400电话中间加上-线

一,代码。

复制代码
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view.
 NSLog(@"--iphone--%@",[self getNewPhoneStr1:@"18502368888"]); } #pragma -mark -functions
//只需传一个电话进去,可以返回一个处理好的加了-线的400电话字符串,如传4001234567,返回400-123-4567
- (NSString *)getNewPhoneStr1:(NSString *)phonestr { if ([phonestr rangeOfString:@"-"].length == 0 && phonestr.length > 6) { NSMutableString *phoneNumber = [NSMutableString string]; NSString *subStr = [phonestr substringToIndex:3]; [phoneNumber appendFormat:@"%@-",subStr]; subStr = [phonestr substringWithRange:NSMakeRange(3, 3)]; [phoneNumber appendFormat:@"%@-",subStr]; subStr = [phonestr substringWithRange:NSMakeRange(6, phonestr.length-6)]; [phoneNumber appendString:subStr]; phonestr = phoneNumber; } return phonestr; }
复制代码

 

二,输出。

2015-10-19 13:52:46.387 将400电话中间加上-线[6123:140629] --iphone--185-023-68888

 

你可能感兴趣的:(【代码笔记】将400电话中间加上-线)