有一个国家代码列表,我需要在每个国家代码上附加表情符号标志。 有没有办法从中提取 unicode 或找到国家代码的表情符号?
这个 npm 示例看起来与我的目标相似(但使用十六进制作为输入)https://github.com/thekelvinliu/country-code-emoji/blob/master/src/index.js
最佳答案
这段代码对我有用。只需将 "US"
替换为您喜欢的任何有效国家代码(基于区域指示符符号字母),它就会创建一个包含该国家/地区国旗表情符号的字符串 flag
。 ( Reference )
int flagOffset = 0x1F1E6;
int asciiOffset = 0x41;
String country = "US";
int firstChar = Character.codePointAt(country, 0) - asciiOffset + flagOffset;
int secondChar = Character.codePointAt(country, 1) - asciiOffset + flagOffset;
String flag = new String(Character.toChars(firstChar))
+ new String(Character.toChars(secondChar));
关于java - 按国家代码获取表情符号标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42234666/