0

I would like to debug emoji icon issue for Android development. My application reads text message from remote server.

String test = String.format("%s",unicodeStr);
Log.i("xxx",test);

I expect it prints something like “\u23434", however it prints "".

So my question is, how could I print out the unicode string as it is?

Thanks a lot.

zhaocong
  • 324
  • 4
  • 9
  • 2
    Add another backslah to your string, like "\"+unicodeStr – Reporter Apr 16 '13 at 10:40
  • @Squonk Java strings are UTF-16 encoded. – R. Martinho Fernandes Apr 16 '13 at 10:47
  • @zhaocong You need to be clearer with your requirements. What input produces that result? And why do you expect such a result? `"\u23434"` is completely unlike ``. What should be printed instead of `"a"`? – R. Martinho Fernandes Apr 16 '13 at 10:54
  • Basically, Java already prints any string "as it is" by default. You will need to ask your question more explicitly. – R. Martinho Fernandes Apr 16 '13 at 11:00
  • See [library-for-converting-native2ascii-and-vice-versa](http://stackoverflow.com/questions/10008989/library-for-converting-native2ascii-and-vice-versa), apache commons StringEscapeUtils.escapeJava. – Joop Eggen Apr 16 '13 at 11:11
  • @R.MartinhoFernandes the "\u23434" is something for clarification only, I want to know what the weird square is encoded with. sorry for my unclear explanation – zhaocong Apr 16 '13 at 12:28
  • The "weird square" is U+E056, a private use character. How it got there no one knows, since we don't know what the input was. You should provide at least an example of input and desired output. – R. Martinho Fernandes Apr 16 '13 at 12:33
  • @reporter how can i add the backslash? the IDE complains `java: illegal escape character` I tried "\"+unicodeStr and unicodeStr.replace("\\","\\\") – zhaocong Apr 16 '13 at 12:36
  • Add the backslash to what? *You still haven't shown what your input is*. – R. Martinho Fernandes Apr 16 '13 at 12:48
  • I asked some colleague about this issue and the are same opinion. Go the same was as Achintya did. The explained me there are two different processes will be started before you will get the binary code. First a 'parser' replaces all special characters. After that a process starts that convert it into binary code. – Reporter Apr 16 '13 at 14:08
  • @R.MartinhoFernandes : Sorry yes, my mistake - it has been a busy day and I'd just been using UTF-8 for a bit of download code. I've deleted my comment. – Squonk Apr 16 '13 at 16:00

2 Answers2

2
String s = "\\u23434";
System.out.println(s);

It prints unicode String as it is.

Achintya Jha
  • 12,735
  • 2
  • 27
  • 39
0

I find an another solution to solve the problem now

for (char curr : str.toCharArray()){
   //print out the character or do whatever you wanna have
   int code = curr;
   Log.i("tag",String.format("%x",code));
}
zhaocong
  • 324
  • 4
  • 9