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?
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
Published March 30, 2021. The Transgender Flag emoji 🏳️⚧️ portrays a flag with pink, blue, and white stripes. This particular flag is used to represent the transgender community and is used to express transgender Pride.
Unicode. The Flag of Russia is represented as the Unicode emoji sequence U+1F1F7 🇷 REGIONAL INDICATOR SYMBOL LETTER R and U+1F1FA 🇺 REGIONAL INDICATOR SYMBOL LETTER U, making "🇷🇺".
You can get the flag of a country by using the two iso alpha2 or alpha3 or the country name or the numeric code.
This code snippet worked for me. Just replace "US"
with whichever valid country code (based on the Regional Indicator Symbol Letters) 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));
This answer helped
function getFlagEmoji(countryCode)
{
const codePoints =
countryCode
.toUpperCase()
.split('')
.map( char => 127397 + char.charCodeAt() );
return String.fromCodePoint(...codePoints);
}
console.log(getFlagEmoji( 'PK' ));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With