FORMAT()

From Lianjapedia
Revision as of 12:09, 13 February 2020 by Barrymavin (Talk | contribs)

Jump to: navigation, search

Purpose

Function to format a string with a variable list of arguments

Syntax

FORMAT(<expC1>[, <exp1> [, <expN>...]])

See Also

AT(), ATNEXT(), CONCAT(), INLIST(), LEFT(), OCCURS(), RAT(), RIGHT(), Server Side Procedures - Parameter Passing Examples, SET STRESCAPE, STR(), STREXTRACT(), STRSTR(), STRTRAN(), STUFF(), SUBSTR()STR_EXPAND()

Description

The FORMAT() function formats the string <expC1> substituting {} parameters with the expressions in the comma-separated list of arguments <exp1> to <expN>. This is similar to C# string formatting.

Also available in JavaScript on desktop, web and mobile. It is particularly useful with the Lianja.evaluate() method when passing parameters to a server-side procedure library from a JavaScript delegate in a web App.

Example

result = format("Hello {0} the number is {1} and the date is {2}", "World", 2020, dtos(date()))
// result: "Hello World the number is 2020 and the date is 20200213"
function page1_section1_eg1()
{
	var cnum1 = "5";
	var cnum2 = "7";
	// Pass as character values for the mylibproc() function in the mylib.prg server-side procedure library
	var evalstring = format("mylib::mylibproc('{0}','{1}')",cnum1,cnum2);
	var result = Lianja.evaluate(evalstring);
	field1.text = field1.text + "\n" + result;
};
 
function page1_section1_eg2()
{
	var num1 = 5;
	var num2 = 7;
	// Pass as numeric values for the mylibproc() function in the mylib.prg server-side procedure library
	var evalstring = format("mylib::mylibproc({0},{1})",num1,num2);
	var result = Lianja.evaluate(evalstring);
	field1.text = field1.text + "\n" + result;
};