Rud*_*dey 7 .net c# unicode char emoji
我有ISO 3166-1 (alpha-2)国家代码,它们是两个字母的代码,例如“US”和“NL”。我如何获得相应的标志表情符号?
编辑:最好我想在不使用国家代码与其相应表情符号之间的显式映射的情况下执行此操作。它已在 JavaScript 中完成,但我不确定如何在 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(); //
Run Code Online (Sandbox Code Playgroud)