如果NSString包含ISO 3166-1 alpha-2双字母国家/地区代码作为唯一输入,请问如何输出包含相应国家/地区的Emoji标志的新NSString?
答案 0 :(得分:1)
+ (NSString*_Nullable) emojiFromCountryCode: (NSString*_Nonnull) countryCode {
/* https://en.wikipedia.org/wiki/Regional_Indicator_Symbol
The regional indicator symbols are a set of 26 alphabetic Unicode characters (A-Z) intended to be used to encode ISO 3166-1 alpha-2 two-letter country codes in a way that allows optional special treatment.
These were defined as part of the Unicode 6.0 support for emoji, as an alternative to encoding separate characters for each country flag. Although they can be displayed as Roman letters, it is intended that implementations may choose to display them in other ways, such as by using national flags.[1][2] The Unicode FAQ indicates that this mechanism should be used and that symbols for national flags will not be directly encoded.[3]
They are encoded in the range U+1F1E6 REGIONAL INDICATOR SYMBOL LETTER A (HTML 🇦) to U+1F1FF REGIONAL INDICATOR SYMBOL LETTER Z (HTML 🇿) within the Enclosed Alphanumeric Supplement block in the Supplementary Multilingual Plane.[4]
*/
NSDictionary* map = @{ @"A" : @"",
@"B" : @"",
@"C" : @"",
@"D" : @"",
@"E" : @"",
@"F" : @"",
@"G" : @"",
@"H" : @"",
@"I" : @"",
@"J" : @"",
@"K" : @"",
@"L" : @"",
@"M" : @"",
@"N" : @"",
@"O" : @"",
@"P" : @"",
@"Q" : @"",
@"R" : @"",
@"S" : @"",
@"T" : @"",
@"U" : @"",
@"V" : @"",
@"W" : @"",
@"X" : @"",
@"Y" : @"",
@"Z" : @""
};
//TRY
return [[map valueForKey: [countryCode substringToIndex: 1]] stringByAppendingString: [map valueForKey: [countryCode substringFromIndex: 1]]];}