iPhone:将Unicode转换为字符串

时间:2011-09-14 05:53:59

标签: unicode-string

我需要将以下内容转换为字符串并显示

Overall, the \u2018\u2018typical\u2019\u2019 xyz is broadly expressed

我尝试过各种非编码转换

NSData *asciiData = [desc dataUsingEncoding:NSASCIIStringEncoding   allowLossyConversion:YES]; 
NSString *encodedString = [[NSString alloc] initWithData:asciiData encoding:NSASCIIStringEncoding

[NSString stringByReplacingOccurrencesOfString:@"\u2018" withString:@""]

没有成功。

请建议我解决这个问题。

1 个答案:

答案 0 :(得分:1)

char cString[] = "\u2018\u2018typical\u2019\u2019";
NSString *string = [NSString stringWithCString:cString encoding:NSUTF8StringEncoding];
NSLog(@"string: %@", string);

NSLog输出:string:''typical''

NSData *data = [NSData dataWithBytes:cString length:strlen(cString)];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"string: %@", string);

NSLog输出:string:''typical''