网上看的
- #import <Foundation/Foundation.h>
- NSString * stringWithoutNum(NSString *str) {
-
- // 从字符串创建一个字符集 是0-9的数字
- NSCharacterSet *numberSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
-
- // 用这个集合里的字符分割字符串为数组元素 然后用@""空字符连接成字符串
- NSString *newStr = [[str componentsSeparatedByCharactersInSet:numberSet] componentsJoinedByString:@""];
-
- return newStr;
- }
- int main() {
- @autoreleasepool {
-
- NSString *str = @"去61掉641所有数416字1665吧";
- NSString *str2 = stringWithoutNum(str);
- NSLog(@"%@", str2);
- }
- return 0;
- }
复制代码 |