Does anyone know How to convert ISO-8859-1开发者_JS百科 encoded string into UTF-8 string or into NSString in Objective C ?
thanks.
Say you have your ISO-8859-1 encoded string in a varaible isoString
of type const char*
, then you can create an NSString instance like this:
NSString* str = [[NSString alloc]
initWithCString: isoString encoding: NSISOLatin1StringEncoding];
Note: Latin-1 and ISO-8859-1 encoding are the same.
With the following code, you can convert it to a UTF-8 encoded C string if needed:
const char* utf8String = [str UTF8String];
Or in one line:
NSString yourFinalString = [NSString stringWithCString:[yourOriginalString cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding];
精彩评论