NSMutableString *mutStr = [NSMutableString string];
for (int i=0; i<s.length; i++) {
NSString *a = [s substringToIndex:i+1];
a = [a substringFromIndex:i];
[mutArrShu addObject:a];
}
for (NSString *b in mutArrShu) {
NSString *emailRegex = @"^[0-9]*$";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
BOOL isShu = [emailTest evaluateWithObject:b];
if (isShu) {
[mutStr appendString:b];
}
}
for (int i=0; i<s.length; i++) {
NSString *a = [s substringToIndex:i+1];
a = [a substringFromIndex:i];
[mutArrShu addObject:a];
}
for (NSString *b in mutArrShu) {
NSString *emailRegex = @"^[0-9]*$";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
BOOL isShu = [emailTest evaluateWithObject:b];
if (isShu) {
[mutStr appendString:b];
}
}
本文介绍了一种使用 Objective-C 编程语言从字符串中提取所有数字的方法。通过遍历字符串并利用正则表达式判断每个字符是否为数字,最终将所有数字字符组合成一个新的字符串。
655

被折叠的 条评论
为什么被折叠?



