I have scandinavian alphabets in my array like æ, ø, å. With NSLog the output showed these alphabets as scrambled codes. How to encode NSArray with UTF8? Any help is appreciated.
I tried only:
NSArray *nnoWords = [[NSArray arrayWithArray:newNoWords] retain];
NSLog (@"nnoWords: %@ ", nnoWords);
newNoWords is a NSMutableArray. nnoWords containt normal objects like NSString hello, pear, apple, etc. taken from a txt file.
EDIT 29 august 2011:
nnoWords comes from this, converted to NSMutable and then back to NSArray, thus called nnoWords. And words.txt is encoded in UTF8.
NSArray *noWords = [[NSArray alloc] initWithArray:
[[NSString stringWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"words" ofType:@"txt"]
encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"]];
I have also tried:
NSString *norsk = @"æ ø å";
NSLog (@"%@", norsk);
And the output is correct:
2011-08-29 13:15:23.302 scanner2[29776:207] æ ø å
The problem is the Xcode console. If you view the output from Terminal.app, you will see it is as expected.
Test case:
Sample output:
If you are still seeing gibberish when you view the output from something other than Xcode’s questionable built-in console, then you need to examine how you’re getting your string data:
filecommand might be able to answer this for you.