Java: Convert String “\uFFFF” into char

前端 未结 4 2051
眼角桃花
眼角桃花 2020-12-03 03:07

Is there a standard method to convert a string like \"\\uFFFF\" into character meaning that the string of six character contains a presentation of one unicode character?

4条回答
  •  佛祖请我去吃肉
    2020-12-03 03:26

    The backslash is escaped here (so you see two of them but the s String is really only 6 characters long). If you're sure that you have exactly "\u" at the beginning of your string, simply skip them and converter the hexadecimal value:

    String s = "\\u20ac";
    
    char c = (char) Integer.parseInt( s.substring(2), 16 );
    

    After that c shall contain the euro symbol as expected.

提交回复
热议问题