我想遍历NSString
,并对每个具有特定条件的单词调用一个自定义函数(例如,“has 2'L's”)。我想知道接近的最好方法是什么。我应该使用查找/替换模式吗?块?在NSString的每个单词上调用一个方法
-(NSString *)convert:(NSString *)wordToConvert{
/// This I have already written
Return finalWord;
}
-(NSString *) method:(NSString *) sentenceContainingWords{
// match every word that meets the criteria (for example the 2Ls) and replace it with what convert: does.
}
对于中文,日文,德文等一些语言来说,空格在单词之间并不是明显的限制,因此Ken的方法是正确的。 – Krodak