Created
April 23, 2014 06:42
-
-
Save AknEp/11204817 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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