iOS 4 以降をターゲットにしている場合は、以下を調べて-enumerateSubstringsInRange:options:usingBlock:
ください。
NSMutableString *string = [NSMutableString stringWithString:@"test this out testers! higher than high. try, trying, tryst."];
NSString *startTag = @"<b>";
NSString *endTag = @"</b>";
NSSet *wordsToMatch = [NSSet setWithObjects:@"test", @"high", @"try", nil];
[string enumerateSubstringsInRange:(NSRange){ .location = 0, .length = [string length] } options:NSStringEnumerationByWords usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
if ([wordsToMatch containsObject:substring]) {
[string insertString:startTag atIndex:substringRange.location];
[string insertString:endTag atIndex:substringRange.location + substringRange.length + startTag.length];
}
}];