I have made an app where I read words from an rtf file
File is loaded through this code
self.germanpath = [[NSBundle mainBundle]pathForResource:@"german" ofType:@"rtf"];
germanfile = [[NSString alloc]initWithContentsOfFile:germanpath encoding:NSUTF8StringEncoding error:&error];
The files contents are
schockierend knusprig das Schachmatt der Schriftsteller getrocknete
Früchte
When I output the string the characters like ü are printing like getrocknete Fr\'fcchte. Both in app and in NSLog statements it is coming as \'.
Edit
I just tried outputting simply
NSLog(@"schockierend knusprig das Schachmatt der Schriftsteller getrocknete Früchte");
and it worked. So I am stating the method I used to output it; I am outputting word by word
NSString *startfrom = [[NSString alloc] initWithFormat:@"german%i",i];
NSString *word = nil;
NSScanner *scanner = [NSScanner scannerWithString:germanfile];
[scanner scanUpToString:startfrom intoString:nil];
[scanner scanUpToString:@" end" intoString:&word];
NSString *finalword = [word substringFromIndex:[startfrom length]];
Word.font = [UIFont fontWithName:@"DK Crayon Crumble" size:25.0];
Word.text = finalword;
NSLog(@"%@",finalword);
[startfrom release];
It’s an RTF file, not a plain text file. Its contents are encoded according to how RTF files are encoded, which involves escaping non-ASCII characters.
Because there’s no native RTF support on iOS (there is on Mac OS X with
NSAttributedString), you would have to roll your own RTF parser in order to read this file. I wouldn’t recommend it. If the RTF file is actually being used to store attributes (such as italic or bold text), you’ll have to go the parser route to convert it to anNSAttributedStringor some other format.If it’s just plain text (and can therefore be fully represented by a Unicode string) then you should recreate the file as a TXT file using a known encoding (such as UTF-8) and then use
-[NSString initWithContentsOfFile:encoding:]to read it.