/
strReplace
strReplace
Description
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 ("") .
Functional area
String
Command syntax
Syntax
strReplace "string" "subStringOld" "subStringNew" |
Arguments
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. |
Flags
None
Return value
string
Returns a new string with the old values replaced with new.
Examples
// 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"
Additional information
Related commands
, multiple selections available,
Related content
strFind
strFind
More like this
strMid
More like this
strLeft
strLeft
More like this
replaceNamespace
replaceNamespace
More like this
strTokArray
strTokArray
More like this
readWord
readWord
More like this