我不認爲這是在SDK中任何東西,但你至少可以使用通過使用類似下面的
NSDictionary *replacements = [NSDictionary dictionaryWithObjectsAndKeys:
@" ", @"<B&",
@" ", @"</B>",
@" ", @"gt;"
@"" , @" Description ",
nil];
return [html stringByReplacingStringsFromDictionary:replacements];
...:
@interface NSString (ReplaceExtensions)
- (NSString *)stringByReplacingStringsFromDictionary:(NSDictionary *)dict;
@end
@implementation NSString (ReplaceExtensions)
- (NSString *)stringByReplacingStringsFromDictionary:(NSDictionary *)dict
{
NSMutableString *string = [self mutableCopy];
for (NSString *target in dict) {
[string replaceOccurrencesOfString:target withString:[dict objectForKey:target]
options:0 range:NSMakeRange(0, [string length])];
}
return [string autorelease];
}
@end
在現代目標C與ARC:此類別所以你可以寫這樣的事情
-(NSString*)stringByReplacingStringsFromDictionary:(NSDictionary*)dict
{
NSMutableString *string = self.mutableCopy;
for(NSString *key in dict)
[string replaceOccurrencesOfString:key withString:dict[key] options:0 range:NSMakeRange(0, string.length)];
return string.copy;
}