Objective-C Unicode 转换成中文

+ (NSString *)replaceUnicode:(NSString *)unicodeStr {
	
	NSString *tempStr1 = [unicodeStr stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"];
	NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
	NSString *tempStr3 = [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];
	NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];
	NSString* returnStr = [NSPropertyListSerialization propertyListFromData:tempData
                                                                                             mutabilityOption:NSPropertyListImmutable 
                                                                                                            format:NULL
                                                                                              errorDescription:NULL];
	
	//NSLog(@"Output = %@", returnStr);
	
	return [returnStr stringByReplacingOccurrencesOfString:@"\\r\\n" withString:@"\n"];
}

 

可以把Unicode格式(\u7E8C)的字符串转换成中文。记录下以备后用。。。

你可能感兴趣的:(C++,c,C#,Objective-C)