How do I log russian text or non-latin?

落爺英雄遲暮 提交于 2019-12-23 03:50:28

问题


Everything works well in the previous version of XCode. But today in the XCode 4.3.2 I have a problem. How do I log russian text or non-latin?

NSLog(@"russian text: русский текст");

NSString *text = @"russian text: русский текст";
const char *textC = [text UTF8String];    
NSString *getText = [NSString stringWithCString:textC encoding:NSUTF8StringEncoding];
NSLog(@"___text: %@", getText);

My logs

russian text: —Ä—É—Å—Å–∫–∏–π —Ç–µ–∫—Å—Ç
___text: russian text: —Ä—É—Å—Å–∫–∏–π —Ç–µ–∫—Å—Ç

UPDATE:

The bug take place only on real device (ipod touch 5.1). It works properly on iphone simulator.


回答1:


Works fine for me in Xcode 4.2, so it's either a 4.3.2 bug or your source file encoding is wrong.

Check the "Preferences / Text Editing / Editing tab / Default text encoding" setting and make sure it's set to Unicode (UTF-8).

If it is, open the file in BBEdit and double check its encoding. It's possible there's an old MacRoman or other encoding set on the file.




回答2:


Update:

Works fine in Simulator for me.

However on a real device running iOS 5.1 I am getting the same wrong, disturbed output as you. So it probably is an XCode 4.3.2 bug.


I tested your code on XCode 4.3.2 and it works fine for me.

My logs:

2012-04-15 15:44:28.545 test[25799:15203] russian text: русский текст
2012-04-15 15:44:28.548 test[25799:15203] ___text: russian text: русский текст



回答3:


I found a solution. You need to change debugger from LLDB to GDB in Product->Edit Sheme. LLDB doesn't work correctly with russian language.



来源:https://stackoverflow.com/questions/10162355/how-do-i-log-russian-text-or-non-latin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!