Last active
October 30, 2015 10:59
-
-
Save cyrilchandelier/26bb28a80eb3f9571e06 to your computer and use it in GitHub Desktop.
Asian characters detection
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
#import <Foundation/Foundation.h> | |
@interface NSString (CJK) | |
/** | |
Detect if the string contains Chinese, Japanese or Korean characters | |
@return YES if the string contains CJK characters, NO otherwise | |
*/ | |
- (BOOL)containsAsianCharacters; | |
@end |
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
#import "NSString+CJK.h" | |
@implementation NSString (CJK) | |
- (BOOL)containsAsianCharacters | |
{ | |
if (![self length]) | |
return NO; | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[\u2E80-\u9FFF]" options:NSRegularExpressionCaseInsensitive error:nil]; | |
return ([regex matchesInString:self options:0 range:NSMakeRange(0, [self length])]); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment