Skip to content

Commit

Permalink
增加 手机号码格式化的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanwei committed Sep 17, 2014
1 parent 3de5a79 commit c20e137
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions util/tools/HKDataUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@
*/
+(NSInteger)getBit:(NSInteger)bitIndex fromByte:(char)byte;

+(NSString *)formattedMobile:(NSString*)mobile;

@end
25 changes: 25 additions & 0 deletions util/tools/HKDataUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,29 @@ +(NSInteger)getBit:(NSInteger)bitIndex fromByte:(char)byte{
return (byte >> bitIndex) & 1;
}

+(NSString *)formattedMobile:(NSString *)mobile{
if (!mobile) {
return @"";
}
NSMutableArray* inputList = [[NSMutableArray alloc] init];
NSInteger len = [mobile length];
for (int i=0; i < len; i++) {
NSString* sub = [mobile substringWithRange:NSMakeRange(i, 1)];
[inputList addObject:sub];
}
NSMutableArray* list = [[NSMutableArray alloc] init];
[list addObjectsFromArray:inputList];
if ([inputList count] > 3) {
[list insertObject:@"-" atIndex:3];
}
if ([inputList count] > 7) {
[list insertObject:@"-" atIndex:8];
}
NSMutableString* sbuf = [[NSMutableString alloc] init];
for (NSString* s in list) {
[sbuf appendString:s];
}
return sbuf;
}

@end

0 comments on commit c20e137

Please sign in to comment.