美文网首页
iOS身份证设置为******

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

作者: Easy_VO | 来源:发表于2016-02-03 19:11 被阅读62次

本来要用正则的,不过后来翻了一下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( , )
//第几位开始,替换几位

相关文章

网友评论

      本文标题:iOS身份证设置为******

      本文链接:https://www.haomeiwen.com/subject/ykjekttx.html