Skip to content

Instantly share code, notes, and snippets.

@AknEp
Created April 23, 2014 06:42
Show Gist options
  • Save AknEp/11204817 to your computer and use it in GitHub Desktop.
Save AknEp/11204817 to your computer and use it in GitHub Desktop.
// How to integrate such two or more methods?
- (NSString *)string:(NSString*)string withoutMatches:(NSArray*)matches
{
NSMutableString *workString = [string mutableCopy];
// 逆順にしないと複数マッチの時に場所がずれる
[matches enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(NSTextCheckingResult* match, NSUInteger idx, BOOL *stop) {
[workString deleteCharactersInRange:match.range];
}];
return [workString copy];
}
- (NSString *)string:(NSString*)string replaceMatches:(NSArray*)matches withReplaceString:(NSString*)replaceString
{
NSMutableString *workString = [string mutableCopy];
// 逆順にしないと複数マッチの時に場所がずれる
[matches enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(NSTextCheckingResult* match, NSUInteger idx, BOOL *stop) {
[workString replaceCharactersInRange:match.range withString:string];
}];
return [workString copy];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment