abhilashca
abhilashca

Reputation: 249

Convert ISO3 country code to ISO2 country code - Windows Phone 8

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.

Upvotes: 2

Views: 2139

Answers (2)

Rene Schulte
Rene Schulte

Reputation: 2962

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.

Upvotes: 2

Kulasangar
Kulasangar

Reputation: 9444

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

Upvotes: 0

Related Questions