@ReplaceSubstring (JavaScript)

リスト内のサブストリングを置き換えます。

定義場所

@Functions (JavaScript)

構文

@ReplaceSubstring(sourceList:any, fromList:any, fromList:any) : any
パラメータ 説明
sourceList 検索するリスト。
fromList 検索サブストリングが含まれるリスト。ここで指定する検索サブストリングは、大文字と小文字の区別を含め、ソースリスト内の要素と正確に一致する必要があります。
toList 置き換え用のストリングが含まれるリスト。このリストは、検索対象のリストと同じ長さで指定する必要があります。
戻り値 説明
any fromList の要素と sourceList の要素を比較し、一致するサブストリング要素がある場合は、sourceList の要素を toList の要素で置き換えて返します。

使用法

リストは配列として操作します。

ストリング要素の一部を置き換える場合に、この関数を使用します。リストの要素全体を置き換える場合は、@Replace (JavaScript) 関数を使用します。

以下の例では、リスト内のサブストリングを置き換えています。
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>>>
*/