objective-c 字符串筛选数字(不使用正则表达式)

来源:互联网 发布:合并矩阵 编辑:程序博客网 时间:2024/05/01 11:58

啥都不说,

直接上代码,注意当遇到转义字符(“\”)前面需要加\注意过滤

NSString *result=@"";    NSString *str=@"abc239-90():!48#%<9*/31\\23";    for (int i=0; i<str.length; i++) {        NSString *s=[str substringWithRange:NSMakeRange(i, 1)];        const char *ch=[s UTF8String];        if (*ch>='0'&&*ch<='9') {            result=[result stringByAppendingString:s];        }    }   NSLog(@"result--------%@",result);

0 0
原创粉丝点击