通过国家/地区代码获取表情符号标志 [英] Get emoji flag by country code

查看:117
本文介绍了通过国家/地区代码获取表情符号标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个国家/地区代码列表,我需要在每个代码上附加表情符号标志.有没有办法从中提取unicode或为国家/地区代码找到表情符号?

There is a list of countries codes, I need to attach emoji flag to each one. Is there a way to extract unicode from it or find emoji for country code?

这个npm示例对于我的目标来说看起来很相似(但使用十六进制作为输入) https://github.com/thekelvinliu/country-code-emoji/blob/master/src/index.js

This npm example looks similar for my goal (but uses hexadecimal as input) https://github.com/thekelvinliu/country-code-emoji/blob/master/src/index.js

推荐答案

此代码段对我有用.只要用您喜欢的任何有效国家代码(基于区域指示符号字母)替换"US" ,它就会创建一个字符串 flag ,其中包含该国家/地区的标志表情符号.(参考)

This code snippet worked for me. Just replace "US" with whichever valid country code (based on the Regional Indicator Symbol Let­ters) you like and it will create a String flag containing the flag emoji for that country. (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));

此答案有所帮助

这篇关于通过国家/地区代码获取表情符号标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆