// 3.实现函数NSString * stringWithoutNum(NSString *str);
// 删除字符串str的所有数字- #import <Foundation/Foundation.h>
- NSString * stringWithoutNum(NSString *str);
- int main(int argc, const char * argv[])
- {
- NSString *s = @"ddfsfds1fdfdsf12dsf12ds1f2ds1f2d1";
- NSString *s2 = stringWithoutNum(s);
- NSLog(@"%@",s2);
- return 0;
- }
- NSString * stringWithoutNum(NSString *str)
- {
- NSMutableString *s = [[NSMutableString alloc] initWithFormat:@"%@",str];
- NSLog(@"%@",s);
- for (int i = 0; i<s.length; i++) {
- char temp = [s characterAtIndex:i];
- if(temp<='9'&&temp>='0')
- {
- [s deleteCharactersInRange:NSMakeRange(i, 1)];
- }
- }
- return s;
- }
复制代码
为什么当连续有两个数字时就删除不了了 |
|