Viewing subset of posts filtered by category.
Posted July 22nd, 2018, last updated July 23rd, 2020 in c-sharp
The Unicode 6.0 spec defines Regional Indicator symbols, which includes a set of flags. Here are the founders of NATO, if your system supports the flag characters (Windows 10 doesn't yet):
🇧🇪 🇨🇦 🇩🇰 🇫🇷 🇮🇸 🇮🇹 🇱🇺 🇳🇱 🇳🇴 🇵🇹 🇬🇧 🇺🇸
To create a flag, take the country ISO code (for example GB), and offset it to the flags Unicode block.
C#
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(); // 🇫🇷
JavaScript
function isoCountryCodeToFlagEmoji(country)
{
return String.fromCodePoint(...[...country.toUpperCase()].map(c => c.charCodeAt() + 0x1F1A5));
}
let gb = isoCountryCodeToFlagEmoji("gb"); // 🇬🇧
let fr = isoCountryCodeToFlagEmoji("fr"); // 🇫🇷