Formatstr – Visara Master Console Center Scripting Guide User Manual
Page 111
Chapter 5 Script Commands
Scripting Guide
111
FORMATSTR
Syntax:
FORMATSTR( $String [, expr1, [expr2, ..., [exprn]..]]) ==> $Formatted
Description:
Formats a string by combining literal characters with conversion
specifications.
Action:
The characters and conversions specified in the String parameter are
processed with any expression parameters to produce a formatted string.
Parameters:
$String. String expression. The string to format that contains the
literal characters and conversion specifications. Each conversion
specification will use zero or more expr parameters.
Expr. Numeric or string expressions. Optional. The values to
substitute into the conversion specifications in the String parameter.
The order of the expression parameters is important—they will be
processed left to right, matching the conversion specifications left to
right in String.
Returns:
String value. The formatted string, with all conversions and
formatting completed.
Notes:
1. The number of expression parameters must match the number of
expressions the String parameter expects in the conversions or
unexpected results will occur.
2. Each expression’s parameter type must match its expected type in
the String parameter.
Example:
//This code segment demonstrates some examples
//of the FORMATSTR function.
//
$MyString := "UNIX Console 22"
%Value := 10
%Value2 := 3
%Value3 := -3
$Return := FORMATSTR( "The value is: %d.", %Value2 )
LOG( LOG_EXEC, $Return, 12 )
OUTPUT=The value is: 3.
$Return := FORMATSTR( "The value is: %+d.", %Value2 )
LOG( LOG_EXEC, $Return, 12 )
OUTPUT=The value is: +3.
$Return := FORMATSTR( "The value is: %+d.", %Value3 )
LOG( LOG_EXEC, $Return, 12 )
OUTPUT=The value is: -3.
$Return := FORMATSTR( "The value is: % d.", %Value2 )
LOG( LOG_EXEC, $Return, 12 )
OUTPUT=The value is: 3.
$Return := FORMATSTR( "The value is: %*d.", %Value,
%Value2 )
LOG( LOG_EXEC, $Return, 12 )
OUTPUT=The value is: 3.