2014-09-20 63 views
0

我有關於轉換的問題。如何將八進制(unicode代碼點)轉換爲iOS中的NSString

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

在Python中,它的工作原理!

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

如何在Objective-C或iOS的Swift中正確轉換它?

回答

1

試試這個:

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

BTW,'的NSLog(@ 「outCommand:%@」,@ 「\ 357 \ 274 \ 221 \ 357 \ 274 \ 221」);'也適用於我的環境。也許它只是包裹在你的輸出控制檯中? – rintaro 2014-09-20 17:03:28

+0

哦,謝謝!也許Xcode或iOS有一個關於字符串的bug,當它附加了一個應用程序進程。它從字符串尾部刪除一個字節。 ('•ω•') – 2014-09-21 02:39:09

相關問題