/// <summary> /// Find the most likely country for a given tail number /// </summary> /// <param name="szTail">The tailnumber, including prefix</param> /// <returns>The countrycodeprefix object representing the best match</returns> public static CountryCodePrefix BestMatchCountryCode(string szTail) { if (szTail == null) { throw new ArgumentNullException(nameof(szTail)); } CountryCodePrefix ccBestMatch = CountryCodePrefix.UnknownCountry; // check for simulator, which isn't in rgcc if (szTail.StartsWith(CountryCodePrefix.szSimPrefix, StringComparison.CurrentCultureIgnoreCase)) { return(CountryCodePrefix.SimCountry); } if (szTail.StartsWith(CountryCodePrefix.szAnonPrefix, StringComparison.CurrentCultureIgnoreCase)) { return(CountryCodePrefix.AnonymousCountry); } IEnumerable <CountryCodePrefix> rgcc = CountryCodePrefix.CountryCodes(); string szCompare = szTail.Replace("-", string.Empty); foreach (CountryCodePrefix cc in rgcc) { if (szCompare.StartsWith(cc.NormalizedPrefix, StringComparison.CurrentCultureIgnoreCase) && cc.NormalizedPrefix.Length > ccBestMatch.NormalizedPrefix.Length) { ccBestMatch = cc; } } return(ccBestMatch); }