Reading unicode character in java

后端 未结 7 819
滥情空心
滥情空心 2020-12-05 22:42

I\'m a bit new to java, When I assign a unicode string to

  String str = \"\\u0142o\\u017Cy\\u0142\";
  System.out.println(str);

  final StringBuilder stri         


        
相关标签:
7条回答
  • 2020-12-05 23:20

    It sounds as though your file literally contains the text z\u0142o\u017Cy\u014, i.e. has Unicode escape sequences in it.

    There's probably a library for decoding these but you could do it yourself - according to the Java Language Specification an escape sequence is always of the form \uxxxx, so you could get the 4-digit hex value xxxx for the character, convert it to an integer with Integer.parseInt, convert it to a character and finally replace the whole \uxxxx sequence with the character.

    0 讨论(0)
提交回复
热议问题