在 PHP 中我可以这样做:
$new = str_replace(array('/', ':', '.'), '', $new);
如何用 Objective-C 将所有包含 / : . 这些字符的地方替换成空(以删除它们)?
我能否在 Objective-C 中轻松实现这一点?还是必须自己编写代码?
目前我正在使用多个 stringByReplacingOccurrencesOfString
调用:
strNew = [strNew stringByReplacingOccurrencesOfString:@"/" withString:@""];
strNew = [strNew stringByReplacingOccurrencesOfString:@":" withString:@""];
strNew = [strNew stringByReplacingOccurrencesOfString:@"." withString:@""];
谢谢,
马特
strNew
是一个NSMutableString
,那么这样做是正确的。但是如果你要使用NSMutableString
,那么最好使用[strNew replaceOccurrencesOfString:@":" withString:@"" options:0 range:NSMakeRange(0, [strNew length])]
。 - user102008