CFLib.org – Common Function Library Project

CodeToCountry(code)

Last updated March 05, 2010

author

Scott Delatush

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Takes a two letter Country Code (i.e. US) and returns the full Country Name (i.e. UNITED STATES). Country Codes are 3166-1-Alpha-2 code (official short names in ENGLISH) see http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html

Return Values:
Returns a string.

Example:

<cfset Country ="US">
    
<cfoutput>
#Country# = #CodeToCountry(Country)#
</cfoutput>

Parameters:

Name Description Required
code Two letter country code you want converted to the country name. Yes

Full UDF Source:

/**
 * Takes a two letter Country Code (i.e. US) and returns the full Country Name (i.e. UNITED STATES).
 * 
 * @param code      Two letter country code you want converted to the country name. (Required)
 * @return Returns a string. 
 * @author Scott Delatush (delatush@yahoo.com) 
 * @version 1, March 5, 2010 
 */
function CodeToCountry(Code) {
  var countries = "AFGHANISTAN,ALBANIA,ALGERIA,AMERICAN SAMOA,ANDORRA,ANGOLA,ANGUILLA,ANTARCTICA,ANTIGUA AND BARBUDA,ARGENTINA,
ARMENIA,ARUBA,AUSTRALIA,AUSTRIA,AZERBAIJAN,BAHAMAS,BAHRAIN,BANGLADESH,BARBADOS,BELARUS,BELGIUM,BELIZE,BENIN,
BERMUDA,BHUTAN,BOLIVIA,BOSNIA AND HERZEGOVINA,BOTSWANA,BOUVET ISLAND,BRAZIL,BRITISH INDIAN OCEAN TERRITORY,
BRUNEI DARUSSALAM,BULGARIA,BURKINA FASO,BURUNDI,CAMBODIA,CAMEROON,CANADA,CAPE VERDE,CAYMAN ISLANDS,CENTRAL AFRICAN REPUBLIC,
CHAD,CHILE,CHINA,CHRISTMAS ISLAND,COCOS (KEELING) ISLANDS,COLOMBIA,COMOROS,CONGO,THE DEMOCRATIC REPUBLIC OF THE CONGO,
COOK ISLANDS,COSTA RICA,CÔTE D'IVOIRE,CROATIA,CUBA,CYPRUS,CZECH REPUBLIC,DENMARK,DJIBOUTI,DOMINICA,DOMINICAN REPUBLIC,
EAST TIMOR,ECUADOR,EGYPT,EL SALVADOR,EQUATORIAL GUINEA,ERITREA,ESTONIA,ETHIOPIA,FALKLAND ISLANDS (MALVINAS),FAROE ISLANDS,
FIJI,FINLAND,FRANCE,FRENCH GUIANA,FRENCH POLYNESIA,FRENCH SOUTHERN TERRITORIES,GABON,GAMBIA,GEORGIA,GERMANY,GHANA,
GIBRALTAR,GREECE,GREENLAND,GRENADA,GUADELOUPE,GUAM,GUATEMALA,GUINEA,GUINEA-BISSAU,GUYANA,HAITI,
HEARD ISLAND AND MCDONALD ISLANDS,HOLY SEE (VATICAN CITY STATE),HONDURAS,HONG KONG,HUNGARY,ICELAND,INDIA,INDONESIA,
ISLAMIC REPUBLIC OF IRAN,IRAQ,IRELAND,ISRAEL,ITALY,JAMAICA,JAPAN,JORDAN,KAZAKSTAN,KENYA,KIRIBATI,
DEMOCRATIC PEOPLE'S REPUBLIC OF KOREA,REPUBLIC OF KOREA,KUWAIT,KYRGYZSTAN,LAO PEOPLE'S DEMOCRATIC REPUBLIC,LATVIA,
LEBANON,LESOTHO,LIBERIA,LIBYAN ARAB JAMAHIRIYA,LIECHTENSTEIN,LITHUANIA,LUXEMBOURG,MACAU,THE FORMER YUGOSLAV REPUBLIC OF MACEDONIA,
MADAGASCAR,MALAWI,MALAYSIA,MALDIVES,MALI,MALTA,MARSHALL ISLANDS,MARTINIQUE,MAURITANIA,MAURITIUS,MAYOTTE,MEXICO,
FEDERATED STATES OF MICRONESIA,REPUBLIC OF MOLDOVA,MONACO,MONGOLIA,MONTSERRAT,MOROCCO,MOZAMBIQUE,MYANMAR,NAMIBIA,NAURU,
NEPAL,NETHERLANDS,NETHERLANDS ANTILLES,NEW CALEDONIA,NEW ZEALAND,NICARAGUA,NIGER,NIGERIA,NIUE,NORFOLK ISLAND,
NORTHERN MARIANA ISLANDS,NORWAY,OMAN,PAKISTAN,PALAU,OCCUPIED PALESTINIAN TERRITORY,PANAMA,PAPUA NEW GUINEA,PARAGUAY,
PERU,PHILIPPINES,PITCAIRN,POLAND,PORTUGAL,PUERTO RICO,QATAR,RÉUNION,ROMANIA,RUSSIAN FEDERATION,RWANDA,SAINT HELENA,
SAINT KITTS AND NEIS,SAINT LUCIA,SAINT PIERRE AND MIQUELON,SAINT VINCENT AND THE GRENADINES,SAMOA,SAN MARINO,
SAO TOME AND PRINCIPE,SAUDI ARABIA,SENEGAL,SEYCHELLES,SIERRA LEONE,SINGAPORE,SLOVAKIA,SLOVENIA,SOLOMON ISLANDS,SOMALIA,
SOUTH AFRICA,SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS,SPAIN,SRI LANKA,SUDAN,SURINAME,SVALBARD AND JAN MAYEN,SWAZILAND,
SWEDEN,SWITZERLAND,SYRIAN ARAB REPUBLIC,TAIWAN PROVINCE OF CHINA,TAJIKISTAN,UNITED REPUBLIC OF TANZANIA,THAILAND,TOGO,
TOKELAU,TONGA,TRINIDAD AND TOBAGO,TUNISIA,TURKEY,TURKMENISTAN,TURKS AND CAICOS ISLANDS,TUVALU,UGANDA,UKRAINE,
UNITED ARAB EMIRATES,UNITED KINGDOM,UNITED STATES,UNITED STATES MINOR OUTLYING ISLANDS,URUGUAY,UZBEKISTAN,VANUATU,
VENEZUELA,VIET NAM,BRITISH VIRGIN ISLANDS,U.S. VIRGIN ISLANDS,WALLIS AND FUTUNA,WESTERN SAHARA,YEMEN,YUGOSLAVIA,ZAMBIA,ZIMBABWE";

  var cCode ="AF,AL,DZ,AS,AD,AO,AI,AQ,AG,AR,AM,AW,AU,AT,AZ,BS,BH,BD,BB,BY,BE,BZ,BJ,BM,BT,BO,BA,BW,BV,BR,IO,BN,BG,BF,BI,KH,CM,CA,CV,KY,CF,TD,CL,CN,CX,CC,CO,KM,CG,CD,CK,CR,CI,HR,CU,CY,CZ,DK,DJ,DM,DO,TP,EC,EG,SV,GQ,ER,EE,ET,FK,FO,FJ,FI,FR,GF,PF,TF,GA,GM,GE,DE,GH,GI,GR,GL,GD,GP,GU,GT,GN,GW,GY,HT,HM,VA,HN,HK,HU,IS,IN,ID,IR,IQ,IE,IL,IT,JM,JP,JO,KZ,KE,KI,KP,KR,KW,KG,LA,LV,LB,LS,LR,LY,LI,LT,LU,MO,MK,MG,MW,MY,MV,ML,MT,MH,MQ,MR,MU,YT,MX,FM,MD,MC,MN,MS,MA,MZ,MM,NA,NR,NP,NL,AN,NC,NZ,NI,NE,NG,NU,NF,MP,NO,OM,PK,PW,PS,PA,PG,PY,PE,PH,PN,PL,PT,PR,QA,RE,RO,RU,RW,SH,KN,LC,PM,VC,WS,SM,ST,SA,SN,SC,SL,SG,SK,SI,SB,SO,ZA,GS,ES,LK,SD,SR,SJ,SZ,SE,CH,SY,TW,TJ,TZ,TH,TG,TK,TO,TT,TN,TR,TM,TC,TV,UG,UA,AE,GB,US,UM,UY,UZ,VU,VE,VN,VG,VI,WF,EH,YE,YU,ZM,ZW";

  if(listFindNoCase(cCode,Code))
    Code=listGetAt(countries,listFindNoCase(cCode,Code));
  return Code;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson