/**
* get the codepoint from the unicode number. from there you can convert it to a unicode escape sequence using {@link JavaUtil#getUnicodeEsq(int)}
* "U+hex" for unicode number
* "&#codePoint;" or "&#hex;" for html
* "\hex" for css
* "hex" for lazyness
*/
public static int parseUnicodeNumber(String num)
{
num = num.toLowerCase();
if(num.startsWith("u+"))
num = num.substring(2);
else if(num.startsWith("&#"))
return num.startsWith("&#x") ? Integer.parseInt(num.substring(3, num.length() - 1), 16) : Integer.parseInt(num.substring(2, num.length() - 1));
else if(num.startsWith("\\"))
num = num.substring(1);
return Integer.parseInt(num, 16);
}
/**
* convert a unicode number directly to unicode escape sequence in java
*/
public static String unicodeNumberToEsq(String num)
{
return toUnicodeEsq(parseUnicodeNumber(num));
}
2条答案
按热度按时间vh0rcniy1#
🦂
(scorpion)是unicode代码点1f982
,即utf-16d83e dd82
,和utf-8f0 9f a6 82
.要将代码点整数转换为unicode转义java字符串,请运行以下代码:
1aaf6o9v2#
在这里,您可以将unicode字符从字符串直接转换为java格式。
我的方法不直接支持unicode数字(u+hex),但是,您可以从css、html和unicode数字格式中逐个获取字符串