iphone; UTF strings from xml
Hi there I have been trying to read an xml file with UTF strings, and am stuck with trying to convert them. My scenario
- Reading xml file from the internet - at times, the xml file contains unicode
- The files read ok, displays ok in the browser
- But when i try to display them - instead of the unicode characters i see ascii converted, something like & #54620;& #54620; [ i added space so that it does'nt display UTF in the post ]
- I tried to ocnvert them into UTF8String using [NSString stringWithUTF8String:[description UTF8String]], but did'nt work
What am i missing here?
edit: If i can understand how to convert a string & #2310;& #2306;& #2358;& #2367;& #2325; & #2313; (ofcourse without the spaces after the &) into its respective UTF symbols (in this case - hindi) - it would be a good start
edit: Sample xml content
descr开发者_开发知识库iption="ख त
" which i would like to convert to UTF characters, i could not find any function to do this conversion
Thanks
Presumably you're reading that XML into an NSData object; it looks like you're converting it to a string somewhere, in description. Try this approach:
NSData *response = [self getXMLData];
NSString *content = [[NSString alloc] initWithBytes:[response bytes]
length:[response length] encoding: NSUTF8StringEncoding];
that should get you a good string with properly formed characters.
精彩评论