I got strings like this from audio stream as titles:
Þòà - Ïàäàòü
I know that this string in russian. And I need to show it correctly in UILabel. I try this:
NSData *data = [value dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Now goodValue
contains next value:
\336\362\340 - \317\340\344\340\362\374
Number of characters as I see the save with original. But how I should convert it into normal string for using as text in UILabel?
Thanks in advance.
I wrote some code for iterating and logging all possible combinations.
At first I found list of all possible encodings in NSString.h and set it to C array of possible encodings:
And now let's iterate and show all possible results:
After that I look through results and found good string. That's all =)
note: all encodings are values of NSStringEncoding enum. And you could think that you could iterate from 0 to number of encodings instead of defining encodings[] array. But you shouldn't do this, because encoding values are not ascending ints. For example NSMacOSRomanStringEncoding = 30 and some of this encoding are aliases for another. Than better to define array of possible encodings.