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