Function: StrSplit
Function: StrSplit

Function: StrSplit

StrSplit ( STRING, DELIMITER )

Splits a string into a series of tokens via a delimiter string.

Parameters

Parameter Type Description
STRING VALUE(STRING) The original string.
STRING VALUE(STRING) The delimiter string for splitting.

Returns

VALUE(LIST) A list of tokens made by splitting the string.

What It Does

This function takes a string and splits it into many strings ("tokens") using a delimiter string as the substring to use for finding the splits. The scan for the delimiter string is case-sensitive, and both parameters are interpreted as strings before the scan and split.


	a = strSplit("apples and pears", " ");              // a = ["apples", "and", "pears"]
	a = strSplit("This:is:separated:by:colons", ":");   // a = ["This", "is", "separated", "by", "colons"]
	a = strSplit(1232123, "2");                         // a = ["1", "3", "1", "3"]

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