IOS如何替换电话号码中间4位为"-"符号


本文实例为大家分享了特殊字符替换电话号码中某一部分的方法,IOS利用-号替换电话号码中间四位,供大家参考,具体内容如下

一、效果图

 

二、代码

RootViewController.m

- (void)viewDidLoad
{
 [super viewDidLoad];
 // Do any additional setup after loading the view.
 
 //电话号码
 UILabel *telLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 200, 20)];
 telLabel.textColor = [UIColor grayColor];
 telLabel.text = @"13793333281";
 //字符串的截取
 NSString *string = [telLabel.text substringWithRange:NSMakeRange(4,4)];
 //字符串的替换
 telLabel.text = [telLabel.text stringByReplacingOccurrencesOfString:string withString:@"----"];
 [self.view addSubview:telLabel];
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持phpstudy。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3