Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSString replace unicode characters

I'w working with a server and I have to download text to my iOS application. Only problem : all characters like "é à ç" are replaced by "\U008" for example. Is there a way to fix this problem, to replace this code by the right character ?

like image 330
Pierre Avatar asked Dec 05 '25 18:12

Pierre


2 Answers

Try to parse the received text (textToParse variable) with this one:

NSString *encodedString = textToParse;
NSString *decodedString = [NSString stringWithUTF8String:[encodedString cStringUsingEncoding:[NSString defaultCStringEncoding]]];
like image 104
Matteo Alessani Avatar answered Dec 08 '25 09:12

Matteo Alessani


I tested some encodings and NSMacOSRomanStringEncoding fit well.

My test was:

NSString *encodedString = [NSString stringWithCString:"Você realmente deseja sair da área restrita" encoding:NSMacOSRomanStringEncoding];

Remember that the message has to be a C-string ("string") and not an NSString(@"string")

like image 35
HeltonRosa Avatar answered Dec 08 '25 08:12

HeltonRosa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!