Java: Convert String “\uFFFF” into char

前端 未结 4 2030
眼角桃花
眼角桃花 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:20

    char c = "\uFFFF".toCharArray()[0];
    

    The value is directly interpreted as the desired string, and the whole sequence is realized as a single character.

    Another way, if you are going to hard-code the value:

    char c = '\uFFFF';
    

    Note that \uFFFF doesn't seem to be a proper unicode character, but try with \u041f for example.

    Read about unicode escapes here

提交回复
热议问题