Alan Edwardes

Cloud Software & Game Development
  • About
  • Projects
  • Contact
  • Blog

About the Author

Alan is a hobbyist Game Developer and a Software Engineer at Autodesk.

Posts in July 2018

  • ISO Country Code to Unicode Flag in C# on the 22nd

Posts in January 2018

  • Serverless Git LFS for Game Development on the 6th
  • Adding Custom Map Checks in UE4 on the 3rd

Posts in December 2017

  • Building and Deploying a React App Using AWS Lambda on the 24th
  • Git HTTP Username and Password in Environment Variables on the 22nd
  • Capturing and Uploading Screenshots in UE4 on the 20th
  • Using Capsule Shadows on Large Objects in UE4 on the 8th

ISO Country Code to Unicode Flag in C#

Posted on July 22nd, 2018 in cloud-software

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. See here for the JavaScript implementation, which I translated to C#.

Code

public static string IsoCountryCodeToFlagEmoji(this string country)
{
    return string.Concat(country.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
}

Usage

string gb = "gb".IsoCountryCodeToFlagEmoji(); // 🇬🇧
string fr = "fr".IsoCountryCodeToFlagEmoji(); // 🇫🇷

Comments

Æ

© 2019 Alan Edwardes