Unable to print russian characters

2019-02-13 14:36发布

I have a russian string which i have encoded to UTF-8

String str = "\u041E\u041A";
System.out.println("String str : " + str);

When i print the string in eclipse console i get ?? Can anyone suggest how to print the russian strings to console or what i am doing wrong here?

I have tried converting it to bytes using byte myArr[] = str.getBytes("UTF-8") and then new String(myArr, "UTF-8") still same problem :-(

6条回答
可以哭但决不认输i
2楼-- · 2019-02-13 14:43

A question: is your console capable of displaying the Russian characters at all?

查看更多
祖国的老花朵
3楼-- · 2019-02-13 14:55

Try this:

String myString = "some cyrillic text";
byte bytes[] = myString.getBytes("ISO-8859-1"); 
String value = new String(bytes, "UTF-8"); 

Or this:

String myString = "some cyrillic text";
byte bytes[] = myString.getBytes("UTF-8"); 
String value = new String(bytes, "UTF-8"); 

The main problem with russian its to set UTF-8 encoding correctly.

查看更多
三岁会撩人
4楼-- · 2019-02-13 14:55

In eclipse Go to Run > Run Configuration > Common > Change the console encoding to UTF-8. You will be able to see the Russian Characters in console

查看更多
冷血范
5楼-- · 2019-02-13 14:57

The display font of the console will most likely not cope with nonASCII characters.

You could try printing to a file rather then System.out

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-02-13 15:03

In XCode you can print values by LLDB function po [SomeClass returnAnObject] For automatic work it can be added in some action in a breakpoint. Also you need add checkbox in "Automatic continue after eval actions"

example

查看更多
Animai°情兽
7楼-- · 2019-02-13 15:06

My Eclipse prints it correctly

String str : ОК

try to change Run Configurations encoding to UTF-8 or CP1251

查看更多
登录 后发表回答