Reading unicode character in java

后端 未结 7 867
滥情空心
滥情空心 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:11

    So, you want to unescape unicode codepoints? There is no public API available for this. The java.util.Properties has a loadConvert() method which does exactly this, but it's private. Check the Java source for the case you'd like to reuse this. It's doing the conversion by simple parsing. I wouldn't use regex for this since this is too error prone in very specific circumstances.

    Or you should probably after all be using java.util.Properties or its i18n counterpart java.util.ResourceBundle with a .properties file instead of a plain .txt file.

    See also:

    • Properties API tutorial
    • Internationalization tutorial - ResourceBundle.

提交回复
热议问题