//取出字串中的數字
第一種:
字串: 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);
複製程式碼