Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can the SilkTest Printf() function be used?

How can the SilkTest Printf() function be used?

The Printf() function is used to print a formatted value to the results file. The user can then specify the format of each argument. The format string can include any Ansi C Printf format specifiers, including:

%s (if the argument that follows is a string)

%d (if the argument that follows is an integer)

%o (if the argument that follows is an integer you want formatted in octal format)

%x (if the argument that follows is an integer you want formatted in hexadecimal format)

%f (if the argument that follows is a real number)

Any of these format characters can be preceded with an integer to specify the width to use in the output. Use an asterisk (*) to determine the width from an argument in the list, for example:

Printf ("%*s", 5, "abc")


The above will print the string "abc" preceded by 5 spaces.

By default, the output is right-justified. A negative width causes left-justification.

For real numbers, a second number can also be specified, which is the precision of the output, in the form width.precision. An asterisk can be used as the precision, to read the precision from the argument list.

Printf does not automatically supply a new-line character at the end of the line, as Print does. To output a carriage return at the end of the line, use the text "\n" in the format string. To output a backslash (\), enter two backslashes in the format string, as in the following:

Printf ("%s\\%s", sMyString, sMyString)


The above will print: abc\abc

Similarly, to output a percent sign (%), specify two percent signs in the format string.

Examples of the use of Printf():

testcase PrintfExample ()
    STRING sMyString = "abc"
    INTEGER iMyInt = 123
    NUMBER nMyReal = 45.7
    Printf ("%s", sMyString)              // prints abc
    Printf ("%4d", iMyInt)                // prints 123
    Printf ("%4.2f", nMyReal)             // prints 45.70
    Printf ("%s%d", sMyString, iMyInt)    // prints abc123
    Printf ("%-4s%d", sMyString, iMyInt)  // prints abc 123

Old KB# 21699

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:23
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.