替换电话号码中间4位为"-"号

这个效果的实现很简单,首先截取需要替换成*号的内容,然后再进行替换
1
2
3
4
5
6
7
8
9
//电话号码
    UILabel *telLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, yy+30, 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];

posted on 2014-07-30 13:47  恒山之阳  阅读(374)  评论(0编辑  收藏  举报

导航