Vicon Shogun banner

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

NameTypeRequiredComments
stringstringyesString to replace sub-strings in.
subStringOldstringyesSub-string to be replaced in string. Can be1 or more characters in length.
subStringNewstringyesString 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