Siebel eScript Language Reference > C Language Library Reference > Clib String Methods >

Clib Write Formatted String Method


The Clib Write Formatted String method writes output to a string variable according to a format that you define. It returns one of the following values:

  • If successful, then it returns the number of characters it wrote in the buffer.
  • If not successful, then it returns the following value:

    EOF

You are not required to define the string value. It is large enough to hold the result.

Format

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

This method performs the same work and uses the same arguments as the Clib Formatted String method except it also includes the stringVar argument. This argument identifies the name of the variable where the Clib Write Formatted String method writes the formatted string. For more information, Clib Get Formatted String Method.

Example

The following example uses the Clib Write Formatted String method with various format string arguments:

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

This example produces the following result:

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

Siebel eScript Language Reference Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.