2

How can I convert ISO-3 country code to ISO-2 country code. For example, I have a string value "USA" which needs to be converted to "US".

I'm getting the 3-digit country code from API (Microsoft.Phone.Maps.Services.MapAddress.CountryCode) as string value, after passing Latitude and Longitude of the location. I checked Windows Phone 8 API stack but couldn't find anything relevant.

Is that possible in Windows Phone 8? Any libraries available to do the same? Any help will be appreciated. Thanks.

abhilashca
  • 249
  • 1
  • 8
  • 21

2 Answers2

2

Seems like you are stuck with a custom mapping on WP.

The native Win NLS API which is mostly available for WP doesn't include the EnumSystemGeoID function to enumerate over all values on WP. 

http://msdn.microsoft.com/en-us/library/windows/desktop/dd317826(v=vs.85).aspx

See c:\Program Files (x86)\Windows Phone Kits\8.0\Include\winnls.h :

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_PC_APP)

WINBASEAPI
BOOL
WINAPI
EnumSystemGeoID(
    _In_ GEOCLASS        GeoClass,
    _In_ GEOID           ParentGeoId,
    _In_ GEO_ENUMPROC    lpGeoEnumProc);

#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_PC_APP) */

That’s likely also why the managed RegionInfo doesn’t provide that ThreeLetterISORegionName property on WP.

Rene Schulte
  • 2,962
  • 1
  • 19
  • 26
0

Looks like there is no built-in way to do that. You can use the approach from the GenericTypeTea's answer. But if you need to convert many country codes you can avoid Cultures enumeration and pre-compute a mapping dictionary for country codes conversion.

Have a look over here Converting country codes in .NET

Community
  • 1
  • 1
Kulasangar
  • 9,046
  • 5
  • 51
  • 82