#import <Foundation/Foundation.h>
NSString * stringWithoutNum(NSString *str);
int main(int argc, const char * argv[]) {
@autoreleasepool {
//3.实现函数NSString * stringWithoutNum(NSString *str);删除字符串str的所有数字
NSString *str = @"hu1f43d5f6dfrgr";
NSString *strnew = stringWithoutNum(str);
NSLog(@"%@", strnew);
}
return 0;
}
NSString * stringWithoutNum(NSString *str)
{
NSMutableString *str1 = [NSMutableString stringWithString:str];
for (int i =0; i< str.length; i++) {
unichar c = [str characterAtIndex:i];
NSRange range = NSMakeRange(i, 1);
if (c >= '0' && c <= '9') {
[str1 deleteCharactersInRange:range];
}
}
NSString *newstr = [NSString stringWithString:str1];
return newstr;
}
运行不对,求大神 |
|