我想在Objective-C中的字符串中替换多个元素。在不过Objective-C字符串替换
str_replace(array("itemtoreplace", "anotheritemtoreplace", "yetanotheritemtoreplace"), "replacedValue", $string);
的Objective-C,我知道的唯一方法就是NSString的replaceOccurancesOfString:
在PHP中,你可以做到这一点。有没有任何有效的方法来取代多个字符串?
这是我目前的解决方案(非常低效和..嗯......长)
NSString *newTitle = [[[itemTitleField.text stringByReplacingOccurrencesOfString:@"'" withString:@""] stringByReplacingOccurrencesOfString:@" " withString:@"'"] stringByReplacingOccurrencesOfString:@"^" withString:@""];
明白我的意思吗?
感谢, 基督教斯图尔特
有没有相当于对象 - 即PHP方法。试着打破你的方法调用三行,所以我们可以看到发生崩溃的确切位置。 – kubi 2010-08-30 01:24:05
Kubi,谢谢你的回答。这并不是真正的困扰我的崩溃。它是整个交易的低效率(如果这是一个字)。 谢谢! Christian – 2010-08-30 01:28:04