Format

Category: Script / Strings
Since engine version: 4.6.5.0 CP

Description

Composes a string of several values. To do this, the specified string is scanned for '%' placeholders which are then replaced by the parameters.
The general syntax for these placeholders is:
%[length][.precision]typeExcept for type all fields are optional. Type specifies the data type of the parameter to be expected. It is one of the following values:
Type Meaning
d Whole number (int)
x Whole number (int), hexadecimal representation (0123456789abcdef)
X Whole number (int), hexadecimal representation (0123456789ABCDEF)
i id (with ids, length and precision parameters do not apply)
s String
v Any. Primarily useful for debugging.
Length specifies the minimum number of characters used to display the value. If the value is shorter, the display is padded on the left with spaces, or with zeroes if there is a '0' before the length specification.

The meaning of the precision field varies with the data type: with integers (d) it specifies the minimum display length (the number is padded with zeroes at the beginning); while with strings (s) it specifies the maximum number of characters to be displayed.

Syntax

string Format (string szStr,  ...);

Parameters

szStr:
String into which to insert values
...:
Values to be inserted

Examples

Message(Format("Hallo, %s. Du hast %d Clonks!", GetPlayerName(0), GetCrewCount(0)));
Displays "Hallo Twonky, du hast 3 Clonks!" (names vary).
Log(Format("'%3d'", 1));
Displays: ' 1'
Log(Format("'%i'", GetID(GetCursor())));
Displays (e.g.): 'CLNK'
Log(Format("'%3.2d'", 5));
Displays: ' 05'
Log(Format("'%.2s'", "test"));
Displays: 'te'
Log(Format("'%03d'", 12));
Displays: '012'
Sven2, November 2001