C object - char from umlaute to NSString

I use libical, which is a library for analyzing the icalendar format (RFC 2445).
The problem is that there may be some German umlaut, for example, in the location field.
Now libical returns const char * for each value, for example:

"K\303\203\302\274nstlerhaus in M\303\203\302\274nchen" 

I tried converting it to NSString with:

 [NSString stringWithCString:icalvalue_as_ical_string_r(value) encoding:NSUTF8StringEncoding]; 

But I get:

 Künstlerhaus in München 

Any suggestions? I would be grateful for any help!

+4
source share
2 answers

It seems that your string got double-encoded UTF-8, because "Künstlerhaus in München" is actually UTF-8, if you decode UTF-8 again, you should get the correct string.

Keep in mind that you should not satisfy this result. There are combinations in which a binary-UTF-8 encoded string cannot be simply decoded by performing double-UTF-8 decoding. Some encoding combinations are irreversible. Therefore, in your situation, I would advise you to find out why the string received UTF-8 double encoding, first of all, it is likely that ical is stored in the wrong encoding on the hard disk, or libical uses the wrong character set to access this, or if you get ical from the server, perhaps the encoding there is incorrect for text / ical, etc. etc.

+6
source

String C does not seem to be encoded in UTF-8, since there are four bytes for each character. For example, ü will be encoded as \xc3\xbc (or \195\188 ) in UTF-8. Thus, the input is either already distorted when you accept it, or it uses some other encoding.

0
source

Source: https://habr.com/ru/post/1395744/


All Articles