Я написал категорию NSString
для этого:
- (NSString *)stringByReplaceCharacterSet:(NSCharacterSet *)characterset withString:(NSString *)string {
NSString *result = self;
NSRange range = [result rangeOfCharacterFromSet:characterset];
while (range.location != NSNotFound) {
result = [result stringByReplacingCharactersInRange:range withString:string];
range = [result rangeOfCharacterFromSet:characterset];
}
return result;
}
Вы можете использовать его так:
NSCharacterSet *funnyCharset = [NSCharacterSet characterSetWithCharactersInString:@"#"];
NSString *newString = [string stringByReplaceCharacterSet:funnyCharset withString:@""];