適用于手機(jī)號(hào)辣往,身份證號(hào)碼殖卑,等敏感號(hào)碼信息部分隱藏
可自定義用來(lái)隱藏占位的字符坊萝、占位起始置位、和占位長(zhǎng)度
ps:同一個(gè)項(xiàng)目里寫了好幾個(gè)方法菩鲜,有隱藏部分手機(jī)號(hào)的惦积,隱藏部分身份證號(hào)的....直接來(lái)一個(gè)總結(jié)。
eg:
Str--原字符串:13866668888
holderSingleStr--占位字符:@"^"
location--占位符起始位置:3
length--占位長(zhǎng)度:4
輸出:138^^^^8888
+ (NSString *)hidePartWithStr:(NSString *)Str holderSingleStr:(NSString *)holderSingleStr location:(NSInteger)location length:(NSInteger)length
{
NSString *hideNumStr = Str;
NSString *placeHolderStr=[NSString string];
if ( [Str isNotBlank] &&[holderSingleStr isNotBlank])//判斷非空
{
for (int i=0; i<length; i++)
{
placeHolderStr = [placeHolderStr stringByAppendingString:holderSingleStr];
}
hideNumStr =[Str stringByReplacingCharactersInRange:NSMakeRange(location, length) withString:placeHolderStr];
}
return hideNumStr;
}