Field-Map Scripting

4.1.2.1 Format

Format function


Prototype:

function Format(s: string; const args: array of const): string;

Description:

The Format function is used to easily construct a formatted string from several values of different types.

"s" is the formatting string; it is basically a template for the output string which contains special patterns (format strings) replaced in the output string with the formatted values taken from the "args" array. Basic format strings are "%d" for integer values, "%s" for string values and "%f" for floating point values. An X.Y modifier can be placed between the "%" sign and the letter specifying the data type. X specifies the formatted width of the value (0 stands for the minimal width) and Y specifies the number of decimal places (e.g. %0.5d, %3.2f etc.)

Syntax:

Format(String,Arguments);


Part

Description


String

A string template containing special patterns to be replaced by actual values


Arguments

An array of values used to replace a special patterns in the template specified by String

Return value:

A formatted string.


Example:

var
  ID: integer;
  Height: double;
  s, Species: string;

begin
  ID := 1;
  Height := 8.5;
  Species := 'pinus pinea';

  s := Format('Species of the tree with ID=%.3d is %s and the height of tree is %0.2f [m]', [ID, Species, Height]);

  ShowInformation(s);        

end.


See also:

Format; LZero; Delete; Trim; TrimLeft; TrimRight; SameText; StringReplace; DeFormat1-10; GetFieldCountFromString;GetFieldFromString; IndexOfField; SortNumericSequence