views:

30

answers:

1

I need to generate rtf-files on iOS-Devices.
As RTF only supports ASCII with escaping, I need to find a solution to escape non-latin characters, so that i.e. ü becomes \'fc, ä \'e4 and ë \'eb

I have following code inside a Category on NSString

self = [NSString stringWithFormat:@"{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard %@ \\par}", self ];
[[self dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES] writeToFile:filenameStr atomically:YES];

but this only turn ü to u, ä to a, etc...

How can I do correct UTF-8 escaping of non-ascii characters?

A: 

I found a solution — at least for my case:

self = [NSString stringWithFormat:@"{\\rtf1\\mac{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard %@ \\par}", self ];
[self writeToFile:filename atomically:YES];
vikingosegundo