美文网首页
从字符串中提取数字

从字符串中提取数字

作者: 哈布福禄克 | 来源:发表于2017-06-22 10:42 被阅读0次

从字符串中提取数字:

-(void)findNumFromStr

{

NSString *originalString = @"a1b2c3d4e5f6g7h8i9j0";

NSMutableString *numberString = [[NSMutableString alloc] init];

NSString *tempStr;

NSScanner *scanner = [NSString scannerWithString:originalString];

NSCharacterSet *numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];

while(![scanner isAtEnd]){

[scanner scanUpToCharactersFromSet:numbers intoString:NULL];

[scanner scanCharactersFromSet:numbers intoString:&tempStr];

[numberString appendString:tempStr];

tempStr = @"";

}

int number = [numberString integerValue];

return number;

}

相关文章

网友评论

      本文标题:从字符串中提取数字

      本文链接:https://www.haomeiwen.com/subject/vunxcxtx.html