Replaces all instances of a sub-string within a string with another string, and returns the resulting string.
The search for subStringOld
is case-sensitive. subStringOld
and subStringNew
do not have to be the same length.
To remove all occurrences of subStringOld
, make subStringNew
an empty string ("") .
String
strReplace "string" "subStringOld" "subStringNew" |
Name | Type | Required | Comments |
---|---|---|---|
string | string | yes | String to replace sub-strings in. |
subStringOld | string | yes | Sub-string to be replaced in string. Can be1 or more characters in length. |
subStringNew | string | yes | String to replace all instances of subStringOld in string. Can be 0 or more characters in length. |
None
string
Returns a new string with the old values replaced with new.
// Demonstrate usage of strReplace string $str = "This is some text"; string $newStr; // Replace "some" with "a bit of" $newStr = `strReplace $str "some" "a bit of"`; print $newStr; // Should be "This is a bit of text" // Remove all occurrences of "i" in the new string $newStr = `strReplace $newStr "i" ""`; print $newStr; // Should be "Ths s a bt of text" // Replace all x's with s's $newStr = `strReplace $str "x" "s"`; print $newStr; // Should be "This is some test" |