I have the following issue:
I enter data in a UITextField and then I want to send it to a server. But the data I am entering may contain umlauts (ö, ä, ü, …). Then I get a wrong encoding when passing it to the server. But I am encoding it with UTF8.
NSString *s = @"ö";
NSLog(@"%@", s);
NSLog(@"%s", s.UTF8String);
What am I doing wrong? In the second line, I see a perfectly fine “ö”, but in the third line, I see this: √∂
There are a lot of encoding posts around the Internet, but nothing really solved the problem.
Are you encoding or decoding things properly when talking to your server?
Remember that NSString has those wonderful functions:
stringByAddingPercentEscapesUsingEncoding:and
stringByReplacingPercentEscapesUsingEncoding:As for seeing garbage in that third NSLog line output, the “%s” in the format means NSLog is expecting a C-style collection of bytes and it might not be able to display high-ascii values properly. Whereas “%@” format in NSLogs means NSString objects and all string encodings should work properly for that.