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

Clib.sprintf() Method

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


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



The string variable to which the output is assigned


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

var1, var2, ..., varn

Variables to be formatted using the formatString


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


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 33 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.


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


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);


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

See Also

Clib.rsprintf() Method

Siebel eScript Language Reference