iOS中可以替换特定位置的字符,所以替换成星号非常简单,简单扩展一下字符串,方法如下:
- (NSString *)replaceStringWithAsterisk:(NSInteger)startLocation length:(NSInteger)length {
NSString *replaceStr = self;
for (NSInteger i = 0; i < length; i++) {
NSRange range = NSMakeRange(startLocation, 1);
replaceStr = [replaceStr stringByReplacingCharactersInRange:range withString:@"*"];
startLocation ++;
}
return replaceStr;
}