String.Format

Top  Previous  Next

 

Syntax

function String.Format(FormatStr: string; val1: variant [; val2: variant; valn: variant; ...]): string

 

Alternative Names

ibec_Format

 

Description

Returns a formatted string with the given values formatted as per FormatStr. The values are listed separately, using val1 and so on.

 

The formatting string can include regular text and format specifiers. Format specifiers are in the form of:

"%" [index ":"] ["-"] [width] ["." prec] type

 

A format specifier begins with a % character, optionally followed by additional formatting options, followed by a type specifier.

 

1.optional zero-offset index specified (first item has an index of 0) to indicate which value to take from the value arguments
2.optional left justification indicator by using the - character
3.optional width specifier
4.optional precision specifier by using the . character following by a numerical value
5.the conversion type character

 

Type

Meaning

d

Decimal, the argument must be an integer value. If the format string contains a precision specifier, the resulting string is at least the specified number of digits, possibly left-padded by zeros.

u

Unsigned decimal, similar to 'd', but no sign is output.

e

Scientific, the argument must be a floating point value.

f

Fixed, the argument must be a floating point value, the number of digits after the decimal character is given by the precision specifier. A default of 2 digits is the default.

g

General, the argument must be a floating point value.

n

Number, similar to f, but with thousand separators.

m

Money, the argument must be a floating point value.

p

Pointer, the argument must be a pointer value.

s

String, the argument must be a string. If a precision identifier is given, the string is truncated to that length.

x

Hexadecimal, the argument must be an integer value. If a precision identifier is given, the output has at least that number of digits and is possibly left-padded with zeros.

 

The decimal separator and thousand separator are taken from the Control Panel and can be modified using Util.SetSystemText.

 

See Also

Util.SetSystemText

 

Example

execute udsblock

as

begin

  /* this formatstr includes literal text and then lists all values */

  valueout = String.Format('These are the values: %d %d %u %s', 5, -10, 10, 'test');

  GUI.ShowMessage(valueout);

 

  /* this formatstr formats a floating point value followed by a text */ 

  valueout = String.Format('%.2f %s', 5.10, 'test');

  GUI.ShowMessage(valueout);

 

  /* this formatstr outputs the given argument 3 times by using the index specifier to indicate the first argument for the 2nd and 3rd format specifier */

  valueout = String.Format('%s %0:s %0:s', 'test');

  GUI.Showmessage(valueout);

end