Can someone please assist me with converting special characters to something that can be correctly represented in an RTF file?
I am taking text stored in a string on the
Check the value of characterAtIndex:
if it is > 127, it is not ASCII, so escape the character.
Something like the following
- (NSString *)stringFormattedRTF:(NSString *)inputString
{
NSMutableString *result = [NSMutableString string];
for ( int index = 0; index < [inputString length]; index++ ) {
NSString *temp = [inputString substringWithRange:NSMakeRange( index, 1 )];
unichar tempchar = [inputString characterAtIndex:index];
if ( tempchar > 127) {
[result appendFormat:@"\\\'%02x", tempchar];
} else {
[result appendString:temp];
}
}
return result;
}