iOS身份证设置为******

本来要用正则的,不过后来翻了一下NSString的方法,替换即可,擦最近老忘事儿,说话也毫无营养,全当记录一下了

/* Replace all occurrences of the target string in the specified range with replacement. 
Specified compare options are used for matching target. If NSRegularExpressionSearch is specified,
 the replacement is treated as a template, 
as in the corresponding NSRegularExpression methods, and no other options can apply except NSCaseInsensitiveSearch and NSAnchoredSearch.
*/
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(NSStringCompareOptions)options range:(NSRange)searchRange NS_AVAILABLE(10_5, 2_0);

/* Replace all occurrences of the target string with replacement. Invokes the above method with 0 options and range of the whole string.
*/
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement NS_AVAILABLE(10_5, 2_0);

/* Replace characters in range with the specified string, returning new string.
*/
- (NSString *)stringByReplacingCharactersInRange:(NSRange)range withString:(NSString *)replacement NS_AVAILABLE(10_5, 2_0);

根据自己的选择和要求进行选取方式吧

NSString *secrectPsID = [sPas.passenger_id_no stringByReplacingCharactersInRange:NSMakeRange(5,9) withString:@"*********"];
DebugLog(@"-----%@",secrectPsID);
cell.detailTextLabel.text = secrectPsID;
//NSMakeRange( , )
//第几位开始,替换几位
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 177,482评论 25 709
  • date:2017-04-03 slide: http://blog.daydaygo.top/post/code...
    daydaygo阅读 784评论 0 0
  • 对之前的试卷进行dom操作,实现必要字段提醒以及打分的功能。实现步骤: 给文本框及选项加id 使用 documen...
    张鸽阅读 278评论 0 0
  • 谁都会有烦恼,每天都有烦恼,最重要的是你不理会烦恼,烦恼自然就没有了! 一定要记住下面的两句话—— 烦恼天天有,不...
    粒粒香阅读 200评论 1 1
  • 等待不是爱情里最可怕的事情,那些充满希望的等待甚至让我愿意小跑着前进,只是我们谁都无法阻止在等待的过程中,命运和机...
    木子皙913阅读 298评论 0 0

友情链接更多精彩内容