Function: StrParam
Function: StrParam

Function: StrParam

StrParam ( STRING, PARAMETERLIST )

Inserts a set of values into a string that contains special tokens, returning a new string.

Parameters

Parameter Type Description
STRING VALUE(STRING) The input string to scan for insert points.
PARAMETERLIST VALUE(LIST) The list of values to insert.

Returns

VALUE(STRING) The resultant string after the replacing.

What It Does

This function takes an input string and finds braced indices in it (e.g. {3}) for replacing each index with the list item that corresponds with it. If the number in the square brackets is not parseable as a positive integer, it is not replaced. Indices that are greater than the list size are read as FALSE.

If the first parameter is not a string, it is interpreted as a string. If the second parameter is not a list, it is converted to a list with the parameter as its only element.

You can output a { by doubling up the brace like so: {{.


	a = strParam("{0} and {1}", ["Apples", "Oranges"]);    // a = "Apples and Oranges"
	a = strParam("{1} and {0}", ["Apples", "Oranges"]);    // a = "Oranges and Apples"
	a = strParam("This is escaped: {{0}", ["Stuff"]);      // a = "This is escaped: {0}"
	a = strParam("{0}, {1}, {2}", ["a", "b"]);             // a = "a, b, false"

Example

String List Function Examples


world
{
	start()
	{
		// strSplit
		textln(strSplit("Apples and Oranges", " "));		// ["Apples", "and", "Oranges"];
		textln(strSplit(1001001, "00"));		            // ["1", "1", "1"];
		textln("");

		// strJoin
		textln(strJoin(["Apples", "and", "Oranges"], "|"));	// "Apples|and|Oranges"
		textln(strJoin([1, 2, 3, 4, 5], ":"));				// "1:2:3:4:5"
		textln(strJoin([[1, 2, 3], [4, 5]], " and "));		// "[1, 2, 3] and [4, 5]"
		textln("");
		
		// strParam
		local tokens = ["Apples", "and", "Oranges"];
		textln(strParam("Hope you like {2} {1} {0}!", tokens));	// "Hope you like Oranges and Apples!"
		textln(strParam("This parameterization does not work: {two} {-1} {5}!", tokens));

		quit;
	}
}
×

Modal Header