Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert ISO-8859-1encoded string into UTF-8 in Objective C

Tags:

iphone

Does anyone know How to convert ISO-8859-1 encoded string into UTF-8 string or into NSString in Objective C ?

thanks.

like image 311
Pratik Goswami Avatar asked Feb 24 '23 13:02

Pratik Goswami


1 Answers

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];
like image 99
Codo Avatar answered Feb 26 '23 04:02

Codo