@Replace (JavaScript)

Replaces strings in a list.

Defined in

@Functions (JavaScript)

Syntax

@Replace(sourceList:any, fromList:any, toList:any) : any
Parameter Description
sourceList The list to be searched.
fromList A list containing the search strings. A search string must exactly match 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 string in fromList replaced by the corresponding element in toList.

Usage

A list is an array.

Use this function to replace entire string elements. To replace parts of strings, use @ReplaceSubstring (JavaScript).

Examples

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

var cities = @List("Moscow", "London", "Moscow", "Moscow");
var from = @List("Paris", "Berlin", "Moscow", "London");
var to = @List("Ps", "Bn", "Mw", "Ln");
cities = @Replace(cities, from, to);
for(var i = 1; i <= @Count(cities); i++) {
	p(i + " " + @Element(cities, i));
}
/*
<<<1 Mw>>>
<<<2 Ln>>>
<<<3 Mw>>>
<<<4 Mw>>>
*/