strformat()
Returns a formatted string.
Synopsis
string strformat( string format, int len, anytype value);
Parameters
Parameter | Description |
---|---|
format | Format of the string |
len | Length of the string |
value | Variables to be used |
Return value
If successful, the formatted string, otherwise an empty string.
Description
strformat() returns a string in accordance with the format stringformatin the lengthlen, while using the variablesvalue. The type ofvalueis automatically recognized. Syntax for the format string:
The format string basically comprises two parts:
<align_switch> <var_format>
The first part <align_switch> defines the alignment of the text and can assume the following values:
\\left \\center \\right \\fill
Parameter | Description |
---|---|
\\left | left-justified |
\\center | centered |
\\right | right-justified |
\\fill | justified |
The second part <var_format> comprises several components:
{[any_string][%<total field_length including commas and digits before the decimal place as well as decimal places>[any_string]}"
The following code lines:
float i;
i=3457.428;
/* The total length is 8 and there are 3 decimal places, therefore the number 8.3 is used*/
DebugN(strformat("\\left{%8.3 Kilometers}", 19, i));
Would look as follows:
WCCOAui1: ["3457.428 Kilometers"]
The following code lines:
float i;
i=1.23;
DebugN(strformat("\\left{Here are%5.2 Kilograms}", 24,i));
/* The total length is 5 since a blank should be added after the word "are". Therefore, the number 5.2 is used (blank1.23). Since two decimal places are output, the number is 5.2*/
Would looks as follows:
WCCOAui1: ["Here are 1.23 Kilograms"]
The any_strings at the beginning and end are directly inserted in front of or after the value, and may, for example, contain the unit of the value.
The following restrictions apply:
<align_switch> is NOT optional, otherwise an empty string is generated!
<align_switch> defines the alignment of the text located between "{" and "}".
Example
main()
{
float i;
i=12.3;
DebugN(strformat("\\left{%5.1 Kilograms}", 15, i));
}
The output looks as follows:
WCCOAui1:[" 12.3 Kilograms"]
Assignment
Strings
Availability
CTRL