@ReplaceSubstring (JavaScript)

Replaces substrings in a list.

Defined in

@Functions (JavaScript)

Syntax

@ReplaceSubstring(sourceList:any, fromList:any, fromList:any) : any
Parameter Description
sourceList The list to be searched.
fromList A list containing the search substrings. A search substring must exactly match a substring in an element in the source list, including case, to obtain a match.
toList A list containing the replacement strings. This list should be the same length as the search list.
Return value Description
any The sourceList with any occurrence of a substring in fromList replaced by the corresponding element in toList.

Usage

A list is an array.

Use this function to replace parts of strings. To replace entire list elements you can use @Replace (JavaScript).

Examples

This example replaces substrings in a list.
function p(stuff) {
	print("<<<" + stuff + ">>>"); 
 }

var cities = @List("The town of Moscow",
	"The town of London",
	"The town of Moscow",
	"The town of Moscow");
var from = @List("town");
var to = @List("city");
cities = @ReplaceSubstring(cities, from, to);
for(var i = 1; i <= @Count(cities); i++) {
	p(i + " " + @Element(cities, i));
}
/*
<<<1 The city of Moscow>>>
<<<2 The city of London>>>
<<<3 The city of Moscow>>>
<<<4 The city of Moscow>>>
*/