Code generator for list of countries

The code generator adds boilerplate code to the text list of countries from Pedro Posada.

The resultant code can then be used for data population into databases or compiled within codes written with a programming language.

See some examples.

Using the code generator

The code generator takes in four input:

  1. Code to appear before the generator loops through the list of country names.
  2. Code to appear while the generator is looping through the list of country names.
  3. Flag to indicate whether the loop should include the last record. This flag is helpful for cases where the boiler plate coding for the last record is different from the rest. The first example demonstrates one such case.
  4. Code to appear after the generator loops through the list of country names.

Within the inputs, the generator recognises three types of format specifiers:

  • %NAME% will be replaced by country names in the list. This format specifier is not available for the first input and for the last input when the “Till the last record” checkbox is unchecked.
  • %NUMBER% will be replaced by a index number. This number starts from 1 and incremented each time the generator loops through a country in the list. This format specifier is not available for the first input and for the last input when the “Till the last record” checkbox is unchecked.
  • %TOTAL% will be replaced by the total number of countries in the list. This format specifier is not available for the second input.

Generate the code

Use %TOTAL% for the total number of countries in the list.

Till the last record

Use %NAME% for country name, %NUMBER% for country number.

Use %TOTAL% for the total number of countries in the list.

Use %NAME% for last country name, %NUMBER% for last country number.

Some examples

1. Insert statements for inserting list of countries into MySQL database

Codes to print before looping:

INSERT INTO `Country` (`number`, `name`) VALUES

Codes to print while looping:

(%NUMBER%, '%NAME%'),

Till the last record: unchecked

Codes to print after looping:

(%NUMBER%, '%NAME%');

2. HTML select element with list of countries as options

Codes to print before looping:

Codes to print while looping:

Till the last record: checked

Codes to print after looping:


3. Java swing JComboBox populated with countries names

Codes to print before looping:

JComboBox countriesComboBox = new JComboBox();

Codes to print while looping:

countriesComboBox.addItem("%NAME%");

Till the last record: checked

Codes to print after looping: Leave blank