【发布时间】:2019-07-03 00:09:50
【问题描述】:
我有以下代码将 unicode 转换为字节,它可以工作:
byte[] emojiBytes = new byte[]{(byte)0xF0,(byte)0x9F,(byte)0x98,(byte)0x81};
String emojiAsString = new String(emojiBytes,Charset.forName("UTF-8"));
// JButton button = new JButton("<html>" + emojiAsString + "</html>");
JButton button = new JButton(emojiAsString);
但如果我只知道这样的 unicode:1F601,1F603,我想在此页面上转换符号:https://apps.timwhitlock.info/emoji/tables/unicode
给定一个像1F601 这样的字符串,我如何将它转换为\xF0\x9F\x98\x81 然后再转换为new byte[]{(byte)0xF0,(byte)0x9F,(byte)0x98,(byte)0x81}?
为了简化,我的代码如下所示:
JButton getButton(String unicodeText)
{
JButton aButton= // how to convert ???
return aButton;
}
那我这样称呼它:JButton myButton=getButton("1F601");
【问题讨论】:
标签: java unicode type-conversion