//取出字符串中的数字
/** ---------------------------------------------------------------------------*/
第一种:
字符串: urlString
NSScanner *scanner = [NSScanner scannerWithString:urlString];
[scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
int number;
[scanner scanInt:&number];
NSString *num=[NSString stringWithFormat:@"%d",number];
/** ---------------------------------------------------------------------------*/
第二种:
字符串: urlString
NSCharacterSet* nonDigits =[[NSCharacterSet decimalDigitCharacterSet] invertedSet];
int remainSecond =[[urlString stringByTrimmingCharactersInSet:nonDigits] intValue];
NSLog(@" num %d ",remainSecond);
iOS---取出字符串中的数字
最新推荐文章于 2023-05-09 18:16:53 发布