# Function Reference

StringReplace

Replaces substrings in a string.

StringReplace ( "string", "searchstring" or start, "replacestring" [, count [, casesense]] )

Parameters

string | The string to evaluate.
searchstring | The substring to search for or the character position to start the replacement.
replacestring | The replacement string.
count | [optional] The number of times to replace the searchstring. 0 = all searchstrings will be replaced (default) [count < 0 also replaces all instances]
casesense | [optional] Flag to indicate if the search operation should be case sensitive. 0 = not case sensitive (default) 1 = case sensitive

Return Value

Returns the new string, the number of replacements performed is stored in @extended.

Remarks

The search/replace is performed left-to-right. Thus, StringReplace("aaa", "aa", "bb") returns "bba"
If the start method is used the count and casesense parameters are ignored. If the replacestring cannot be stored a blank string is returned and @error is set to 1.

Related

String, StringLeft, StringLen, StringLower, StringMid, StringRight, StringTrimLeft, StringTrimRight, StringUpper

Example

$text = StringReplace("this is a line of text", " ", "-")
$numreplacements = @extended
MsgBox(0, "New string is", $text)
MsgBox(0, "The number of replacements done was", $numreplacements)