Brian Dunning's FileMaker Custom Functions

GetCountryCodeFromCountry ( Country )

Get Country Code from Full Country Name

  Average rating: 2.4 (195 votes) Log in to vote

Andy Knasinski   Andy Knasinski - Show more from this author
nrg software, llc.
http://www.nrgsoft.com

Share on Facebook Share on Twitter

  Sample input:
GetCountryCodeFromCountry ( "Yemen" )
  Sample output:
YE

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Convert country names to ISO country codes

 

Comments

Jack   Jack, London
Aug 30, 2011
No case checking? Yikes!
 
Andy   Andy
Aug 30, 2011
?? FMP is is not case sensitive for these comparisons.
 
Ward   Ward, Massachusetts, USA
Nov 30, 2012
FileMaker Pro 11 Advanced chokes on this line:

Country = "S„o TomÈ and PrÌncipe" ; "ST" ;

I replaced the accented name with "Sao Tome and Principe" from Wikipedia's ISO 31166-1 alpha-2 page:

http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
 
Robert Woodhead   Robert Woodhead, Wilmington, NC
Jul 2, 2014
Handy function, but needs some updates to handle variants. Here are the edits.

GetCountryCodeFromCountry ( CountryName )

Let(Country=
Substitute(
Substitute(
Substitute(
Substitute(
if(Left(CountryName,4)="The ",Right(CountryName,Length(CountryName)-4),CountryName)
;" & ";" and ")
;"&";" and ")
;" ";" ")
;" ";" ");
Case ( ... case list ...

""
))

And add the following case variants

Country = "Palestine" ; "PS" ;
Country = "Russian Federation" ; "RU" ;
Country = "Great Britain" ; "GB" ;
Country = "Great Britain and Northern Ireland" ; "GB" ;
Country = "United States" ; "US" ;
Country = "USA" ; "US" ;
Country = "Sao Tome and Principe" ; "ST" ;
Country = "Cocos Islands" ; "CC" ;
Country = "Keeling Islands" ; "CC" ;
Country = "Democratic Republic of the Congo" ; "CD" ;
Country = "Republic of the Congo" ; "CG" ;
Country = "Falkland Islands (Malvinas)" ; "FK" ;
Country = "Falkland Islands" ; "FK" ;
Country = "Malvinas" ; "FK" ;
Country = "Vatican City" ; "VA" ;
Country = "The Vatican" ; "VA" ;
Country = "The Former Yugoslav Republic of Macedonia" ; "MK" ;
Country = "Macedonia" ; "MK" ;
Country = "Micronesia, Federated States of" ; "FM" ;
Country = "Federated States of Micronesia&qu
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: