简体   繁体   中英

Spanish character encoding - iphone

I am sending text from iphone to the server for processing. The text contain some spanish characters eg, á é í ó ú ü ñ ¿ ¡ ºª

While sending, I am encoding it with NSUTF8StringEncoding Server side is also using UTF8 encoding to decode it.

But the server side decodes it as ???????

Please let me know if anyone has faced this issue and how this was resolved ?

Thanks.

I found the solution.

Since this is a post data I had to escape the special characters.

stringByAddingPercentEscapesUsingEncoding: doesn't seem to escape all the special characters. I faced this issue with "+" character where it was getting replaced by a whitespace.

I feel same thing happens with spanish character where it is not escaped properly, so I manually replaced it and it worked.

following is an example. I wrote this for all the characters

escapedString = [escapedString stringByReplacingOccurrencesOfString:@"À" withString:@"%C0"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Á" withString:@"%C1"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Â" withString:@"%C2"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Ã" withString:@"%C3"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Ä" withString:@"%C4"];

Thank you xj1200 and saadnib for looking in to this. I really appreciate. If you guys find any other better solution please post.

I think you can use Google Toolbox for Mac for ancoding these characters. See files GTMNSString+

http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/?r=27#trunk%2FFoundation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM