I have ISO 3166-1 (alpha-2) country codes, which are two-letter codes, such as "US" and "NL". How do I get the corresponding flag emoji?
EDIT: Preferably I would like to do this without using an explicit mapping between country codes and their corresponding emojis. It has been done in JavaScript but I'm not sure how to do it in C#.
This emoji is named "green flag" and is licensed under the open source Creative Commons Attribution 4.0 International license. It's a colored emoji. It's also a defined emoji, which means it's part of the open standard on emojis.
While U.S. state flags won't be added by the Unicode Consortium, vendors are free to design their own flag emoji for states and other subdivisions.
Solution:
public static string IsoCountryCodeToFlagEmoji(this string country)
{
return string.Concat(country.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
}
string gb = "gb".IsoCountryCodeToFlagEmoji(); // 🇬🇧
string fr = "fr".IsoCountryCodeToFlagEmoji(); // 🇫🇷
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