iOS 字符串去除中文

+ (NSString *)deleteChineseStringWithString:(NSString *)string {
    for (int i=0; i < string.length; i++) {
        int utfCode = 0;
        void *buffer = &utfCode;
        NSRange range = NSMakeRange(i, 1);
        BOOL b = [string getBytes:buffer maxLength:2 usedLength:NULL encoding:NSUTF16LittleEndianStringEncoding options:NSStringEncodingConversionExternalRepresentation range:range remainingRange:NULL];
        if (b && (utfCode >= 0x4e00 && utfCode <= 0x9fa5)) {
            string = [string stringByReplacingCharactersInRange:range withString:@""];
        }
    }
    return string;
}

你可能感兴趣的:(iOS 字符串去除中文)