0

I have the following char[] str = "\xe7a";

This is the result of having converted "ça" into unicode escaped with python .encode('unicode-escape')

When it gets to iOS I'm trying to convert it to "ça" again... but I can't find the right method to do it.

How can I convert \x escaped characters into their proper characters using iOS functions?

str = [[NSString alloc] initWithBytes:m.param5 length:STRING_PARAM_LENGTH encoding:NSASCIIStringEncoding] UTF8String];

doesn't work

str = [[NSString alloc] initWithBytes:m.param5 length:STRING_PARAM_LENGTH NSUTF8StringEncoding];

doesn't work

str = [NSString stringWithUTF8String:m.param5];

doesn't work as well

Any ideas?

laxonline
  • 2,657
  • 1
  • 20
  • 37
Nuno Santos
  • 1,476
  • 3
  • 17
  • 34
  • You can think about CFStringTransform. Check [THIS](http://stackoverflow.com/questions/2099349/using-objective-c-cocoa-to-unescape-unicode-characters-ie-u1234/11615076#11615076) – Oh Seung Kwon Feb 06 '13 at 08:35

1 Answers1

2

Assuming \xe7 means the byte 0xe7, the char array is encoded as Windows-1252/ISO-8859-1... so:

NSString *string = [NSString stringWithCString:str encoding:NSISOLatin1StringEncoding];

If the contents are literally a backslash, x, e, and 7, you need to turn that into the real implied byte value before running the above code

Esailija
  • 138,174
  • 23
  • 272
  • 326