ISO Country Code to Unicode Flag in C♯ and JavaScript
ā ļø This post was last updated in 2021, meaning its contents may be outdated.
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"); // š«š·
š·ļø flag unicode iso country code c♯ javascript specification regional indicator symbol nato character windows gb
Please click here to load comments.