Search code examples
iosstringnsstringnslogoctal

How to convert octal (unicode code point) to NSString in iOS


I have a problem about converting.

print "\357\274\221\357\274\221" # 11 , no problem!

In python, it works!

NSLog(@"outCommand:%@", @"\357\274\221\357\274\221");// 1 , loses another letter!
NSLog(@"outCommand:%@", [@"\357\274\221\357\274\221" dataUsingEncoding:NSUTF8StringEncoding]);// <efbc91ef bc91>

How can I convert it correctly in Objective-C or Swift on iOS?


Solution

  • Try this:

    char buf[]="\357\274\221\357\274\221";
    NSString *str = [NSString stringWithUTF8String:buf];
    NSLog(@"%@", str);