@Explode (JavaScript)

Parses a string into elements in a list using specified separators.

Defined in

@Functions (JavaScript)

Syntax

@Explode(value:string) : any

@Explode(value:string, separators:string) : any

@Explode(value:string, separators:string, incEmpties:int) : any

@Explode(value:string, separators:string, incEmpties:int, newLineAsSeparator:int) : any

Parameter Description
value The string to be parsed.
separators A series of characters treated as separators. These characters delimit elements and do not appear in the output. The default separators are ",; " (comma, semicolon, space). The newline is automatically a separator unless excluded by the last parameter.
incEmpties 0 (default) to ignore leading, trailing and multiple consecutive separators or 1 to insert empty strings. (Note: this option may fail to process elements following multiple consecutive separators so is not recommended.)
newLineAsSeparator 1 (default) to treat the newline as a separator or 0 to treat it as text.
Return value Description
any The resulting list.

Usage

A list is an array.

Examples

This example explodes a string into a list using the default separators.
function p(stuff) {
	print("<<<" + stuff + ">>>"); 
 }

var citiesString = new String("Paris,Berlin,London,Moscow");

p(citiesString);
var citiesArray = @Explode(citiesString);
for(var i = 1; i <= @Elements(citiesArray); i++) {
	p(@Element(citiesArray, i));
}
/* Log output
<<<Paris,Berlin,London,Moscow>>>
<<<Paris>>>
<<<Berlin>>>
<<<London>>>
<<<Moscow>>>
*/

This example explodes a string into a list using specified separators.

function p(stuff) {
	print("<<<" + stuff + ">>>"); 
 }

var citiesString = new String("Paris.Berlin.London.Moscow");

p(citiesString);
var citiesArray = @Explode(citiesString, ", ;.");
for(var i = 1; i <= @Elements(citiesArray); i++) {
	p(@Element(citiesArray, i));
}
/* Log output
<<<Paris.Berlin.London.Moscow>>>
<<<Paris>>>
<<<Berlin>>>
<<<London>>>
<<<Moscow>>>
*/

This example explodes a string into a list using specified separators that excludes the newline.

function p(stuff) {
	print("<<<" + stuff + ">>>"); 
 }

var citiesString = new String("Paris,Berlin\nLondon,Moscow");

p(citiesString);
var citiesArray = @Explode(citiesString, ", ;.", @False(), @False());
for(var i = 1; i <= @Elements(citiesArray); i++) {
	p(@Element(citiesArray, i));
}
/* Log output
<<<Paris,Berlin
London,Moscow>>>
<<<Paris>>>
<<<Berlin
London>>>
<<<Moscow>>>
*/