Created
December 18, 2020 06:25
-
-
Save lyleLH/88f4a587e1a018cae02eeedbfa099513 to your computer and use it in GitHub Desktop.
将版本号字符串 转换为整数字符串
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSString *)versionStrtingToNumberString:(NSString*)versions { | |
NSArray <NSString *>*arry=[versions componentsSeparatedByString:@"."]; | |
NSMutableArray * numberAry = [[NSMutableArray alloc] initWithCapacity:6]; | |
// for (NSString *i in arry){ | |
// NSLog(@"%@",i); | |
// } | |
for (NSInteger i =0; i <arry.count; i ++) { | |
if(arry[i].length==1){ | |
if(i==2){ | |
[numberAry insertObject:@"0" atIndex:2*i]; | |
[numberAry insertObject:arry[i] atIndex:2*i+1]; | |
}else{ | |
[numberAry insertObject:arry[i] atIndex:2*i]; | |
[numberAry insertObject:@"0" atIndex:2*i+1]; | |
} | |
}else if(arry[i].length==2){ | |
if(i==2){ | |
NSMutableArray *letterArray = [NSMutableArray array]; | |
[arry[i] enumerateSubstringsInRange:NSMakeRange(0, [arry[i] length]) | |
options:(NSStringEnumerationByComposedCharacterSequences) | |
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | |
[letterArray addObject:substring]; | |
}]; | |
[numberAry insertObject:letterArray[1] atIndex:2*i]; | |
[numberAry insertObject:letterArray[0] atIndex:2*i+1]; | |
}else{ | |
NSMutableArray *letterArray = [NSMutableArray array]; | |
[arry[i] enumerateSubstringsInRange:NSMakeRange(0, [arry[i] length]) | |
options:(NSStringEnumerationByComposedCharacterSequences) | |
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | |
[letterArray addObject:substring]; | |
}]; | |
[numberAry insertObject:letterArray[0] atIndex:2*i]; | |
[numberAry insertObject:letterArray[1] atIndex:2*i+1]; | |
} | |
} | |
} | |
// NSLog(@"------------------"); | |
// for (NSString *i in numberAry){ | |
// NSLog(@"%@",i); | |
// } | |
NSMutableString * result = [[NSMutableString alloc] init]; | |
for (NSObject * obj in numberAry) | |
{ | |
[result appendString:[obj description]]; | |
} | |
NSLog(@"%@",result); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment