我将需要替换脏字符串以获得干净的字符串:
-(void)setTheFilter:(NSString*)filter { [filter retain]; [_theFilter release]; <PSEUDO CODE> tmp = preg_replace(@"/[0-9]/",@"",filter); <~PSEUDO CODE> _theFilter = tmp; }
这应该消除过滤器中的所有数字,以便:
@ “Import6652”
会产生@“导入”
我怎么能在iOS中做到这一点?
谢谢!
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern: @"([0-9]+)" options:0 error:nil]; [regex replaceMatchesInString:str options:0 range:NSMakeRange(0,[str length]) withTemplate:@""];
迅速
do { let regex = try NSRegularExpression(pattern: "([0-9]+)",options: NSRegularExpressionOptions.CaseInsensitive) regex.replaceMatchesInString(str,options: NSMatchingOptions.ReportProgress,range: NSRange(0,str.characters.count),withTemplate: "") } catch {}