.h文件
[objc] view plain copy
- <span style="font-size:18px;">/**
- * 转成星号工具
- */
- @interface AsteriskTool : NSObject
- //把手机号第4-7位变成星号
- +(NSString *)phoneNumToAsterisk:(NSString*)phoneNum;
- //把手机号第5-14位变成星号
- +(NSString *)idCardToAsterisk:(NSString *)idCardNum;
- @end
.m文件
[objc] view plain copy
- <span style="font-size:18px;">@implementation AsteriskTool
- +(NSString *)phoneNumToAsterisk:(NSString*)phoneNum
- {
- return [phoneNum stringByReplacingCharactersInRange:NSMakeRange(3,4) withString:@"****"];
- }
- +(NSString*)idCardToAsterisk:(NSString *)idCardNum
- {
- return [idCardNum stringByReplacingCharactersInRange:NSMakeRange(4, 10) withString:@"**********"];
- }
- @end
这个用的是nsstring的替换,
时间: 2024-10-12 10:58:24