NSString * str = @"123/21年123"; NSCharacterSet *nonDigitCharacterSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet]; //获取字符串中的数字 str = [[str componentsSeparatedByCharactersInSet:nonDigitCharacterSet] componentsJoinedByString:@""]; NSLog(@"结果是:%@",str);
鸣谢:https://www.cnblogs.com/lulushen/p/9884873.html
来源:https://www.cnblogs.com/gaozhang12345/p/11331665.html