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 set of found characters with. |
VALUE(STRING) | The resultant string from replacing the found sequence of characters with the replacement. |
This function searches the first string for a sequence of characters and, if found, replaces the sequence with the replacement string, and returns the result. All provided values are interpreted as strings before the check. The check is case-sensitive. Only the last occurrence of the sequence in the first string is replaced - the search starts from the end of the string.
If the sequence to search for is not found, the original string is returned.
a = strReplaceLast("tomato", "to", "__"); // a = "toma__"
a = strReplaceLast("Apples to Apples", "Apples", "Grapes"); // a = "Apples to Grapes"
a = strReplaceLast(12345, 12, "__"); // a = "__345"
a = strReplaceLast(100.003, "00", "__"); // a = "100.__3"
a = strReplaceLast("ABCDEFG", "a", "_"); // a = "ABCDEFG"
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;
}
}