私が直接Unicodeを入力するなどの方法でString
に変換する場合、私は絵文字を見ることができます:stringbufferを文字列に変換しましたが、stringをunicode intに変換する方法はありますか?
int intUnicode = 0x1F601;
public String getEmojiByUnicode(int unicode) {
return new String(Character.toChars(unicode));
}
しかし、私はちょうどユニコード値のようなString
ときに変換する方法のまわりで私の頭をラップすることはできません。私は直接それをやったようInteger
にそれをひそかする方法
String strUnicode = "0xf601";
。 Integer.parseInt(strUnicode)
コンパイラを使用しようとすると、毎回エラーが発生します。
InputStream is = assetManager.open("emoji_unicode.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
if (is != null){
try {
while ((data = reader.readLine()) != null){
sbuffer.append(data + "\n");
String j = sbuffer.toString().trim();
int k = Integer.parseInt(j,16);
String l = getEmojiByUnicode(k);
emoArray.add(l);
}
btn.setText(emoArray.get(5));
is.close();
}catch (IOException e){
e.printStackTrace();
}
}
非常に難しいことではありませんが、私は非常に近いと思っていますが、それでも私には届きません。どんな助けでも大歓迎です。 リガード
あなたのUnicode文字列はあなたの最初の例で生成したものと同じではありません。あなたは[UTF-16](https://en.wikipedia.org/wiki/UTF-16)エンコーディングを見て、それが[あなたが使っている範囲]のコードポイントにどのように適用されるかを見てください(https: //en.wikipedia.org/wiki/UTF-16#U+10000_to_U+10FFFF)。あなたが与えている文字列が有効なUTF-16でないため、あなたのコンパイラは不平を言っています。 – Jules
[16進文字列を整数に解析すると、NumberFormatExceptionがスローされる可能性がありますか?](https://stackoverflow.com/questions/11377944/parsing-a-hexadecimal-string-to-an-integer-throws-a-numberformatexception) –