Siebel eScript Language Reference > Siebel eScript Commands > Clib Object String Methods >

Clib.sprintf() Method


This method writes output to a string variable according to a prescribed format.

Syntax

Clib.sprintf(stringVar, formatString, var1, var2, ..., varn)

Parameter
Description

stringVar

The string variable to which the output is assigned

formatString

A string indicating how variable or literal parameters are to be treated

var1, var2, ..., varn

Variables to be formatted using the formatString

Returns

The number of characters written into buffer if successful; otherwise, EOF.

Usage

This method formats the values in the variables according to formatString and assigns the result to stringVar. The formatString contains character combinations indicating how following parameters are to be treated. For information on format strings used with Clib.sprintf(), see Table 34 in the section Clib.asctime() Method. The string value need not be previously defined; it is created large enough to hold the result. Characters are printed as read to standard output until a percent character (%) is reached. The percent character indicates that a value is to be printed from the parameters following the format string.

Example

The following examples show Clib.sprintf() used with various format string parameters. Trace file output follows after the script.

TheApplication().TraceOn("c:\\eScript_trace.txt","allocation","all");

var a, b, c;
a = 5;
b = 2;

Clib.sprintf(c, "First # %d + Second # %d is equal to %03d",a,b, a+b);
TheApplication().Trace("Output : " + c);

Clib.sprintf(c, "\n First # %d \n Second # %d \n => %d",12,16, 12+16)
TheApplication().Trace("Output : " + c);

var x, y, z, n;
var x = "Ali is 25 years old";
var y = "he lives in Ireland.";
var n = Clib.sprintf(z, "\n %s and %s",x,y) ;

TheApplication().Trace("Output : " + z);
TheApplication().Trace("Total characters: " + n);

var a = 16.51;
var b = 5.79;
var c;

Clib.sprintf(c, "%.3f / %.3f is equal to %0.3f",a,b, parseFloat(a/b));
TheApplication().Trace("Output : " + c);

TheApplication().TraceOff();

The script produces the following trace output.

02/18/04,18:37:35,START,7.5.3 [16157] LANG_INDEPENDENT,SADMIN,3964,3836
02/18/04,18:37:35,COMMENT,Output : First # 5 + Second # 2 is equal to 007
02/18/04,18:37:35,COMMENT,"Output :
First # 12
Second # 16
=> 28"
02/18/04,18:37:35,COMMENT,"Output :
Ali is 25 years old and he lives in Ireland."
02/18/04,18:37:35,COMMENT,Total characters: 46
02/18/04,18:37:35,COMMENT,Output : 16.510 + 5.790 is equal to 2.851
02/18/04,18:37:35,STOP

See Also

Clib.rsprintf() Method

Siebel eScript Language Reference Copyright © 2007, Oracle. All rights reserved.