- (void)setContent:(NSString *)content
{
NSArray *array=[content componentsSeparatedByString:@"&"];
NSMutableString *string=[NSMutableString new];
for (int i = 0; i < array.count; i++) {
NSString *chineseStr = [self getChineseStringWithString:array[i]];
if (chineseStr.length>0) {
[string appendString:chineseStr];
[string appendString:@";"];
}
}
_content = string;
} - (NSString *)getChineseStringWithString:(NSString *)string
{
//(unicode中文编码范围是0x4e00~0x9fa5)
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)) {
return [string substringFromIndex:i];
}
}
return nil;
}
网友评论