Function: StrReplaceAll
Function: StrReplaceAll

Function: StrReplaceAll

StrReplaceAll ( STRING, SEQUENCE, REPLACEMENT )

Replaces every occurrence of a sequence of characters in a string with the replacement string.

Parameters

Parameter Type Description
STRING VALUE(STRING) The string to search in.
SEQUENCE VALUE(STRING) The character sequence to search for.
REPLACEMENT VALUE(STRING) The string to replace the sets of found characters with.

Returns

VALUE(STRING) The resultant string from replacing every found sequence of characters with the replacement.

What It Does

This function searches the first string for every sequence of characters and, when found, replaces each sequence with the replacement string, and returns the result. All provided values are interpreted as strings before the check. The check is case-sensitive.

If no occurrences of the provided search sequence are found, the original string is returned.


	a = strReplaceAll("tomato", "to", "__");                    // a = "__ma__"
	a = strReplaceAll("Apples to Apples", "Apples", "Grapes");  // a = "Grapes to Grapes"
	a = strReplaceAll(12345, 12, "__");                         // a = "__345"
	a = strReplaceAll(100.003, "00", "__");                     // a = "1__.__3"
	a = strReplaceAll("ABCDEFG", "a", "_");                     // a = "ABCDEFG"

Example

String Replace Examples


world
{
	start()
	{
		// Replace
		textln(strReplace("Apples and Pears", "Apples", "Oranges"));
		textln(strReplace("Apples and Apples", "Apples", "Oranges"));
		textln(strReplace("Kiwis and Lemons", "Grapefruits", "Peaches"));
		textln(strReplace(100, 0, "Zero"));
		textln("");

		// Replace Last
		textln(strReplaceLast("Apples and Pears", "Apples", "Oranges"));
		textln(strReplaceLast("Apples and Apples", "Apples", "Oranges"));
		textln(strReplaceLast("Kiwis and Lemons", "Grapefruits", "Peaches"));
		textln(strReplaceLast(100, 0, "Zero"));
		textln("");

		// Replace All
		textln(strReplaceAll("Apples and Pears", "Apples", "Oranges"));
		textln(strReplaceAll("Apples and Apples", "Apples", "Oranges"));
		textln(strReplaceAll("Kiwis and Lemons", "Grapefruits", "Peaches"));
		textln(strReplaceAll(100, 0, "Zero"));

		quit;
	}
}
×

Modal Header