从NSString中提取数字

- (NSArray *)getOnlyNum:(NSString *)str
{

    NSString *onlyNumStr = [str stringByReplacingOccurrencesOfString:@"[^0-9,]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [str length])];
    NSArray *numArr = [onlyNumStr componentsSeparatedByString:@","];
    return numArr;
}


 testStr *str = [[testStr alloc]init];
        NSString *testStr = @"111111(哈哈),22222222222<各个>,3333333333[订单],44444444";
        NSLog(@"结果为:%@",[str getOnlyNum:testStr]);

输出结果:

2013-05-14 14:54:00.306 test[3559:303] 结果为:(

    111111,

    22222222222,

    3333333333,

    44444444

)

 

posted @ 2013-05-14 14:53  菜鸟程序猿  阅读(1398)  评论(0编辑  收藏  举报