String.ReplaceAll

From Xojo Documentation

Method

String.ReplaceAll(substring As String, replacementString As String) As String

Supported for all project types and targets.

Replaces all occurrences of a string with another string.

Usage

result = sourceVariable.ReplaceAll(oldString, newString)

Part Type Description
result String A copy of sourceVariable with any changes made by the ReplaceAll function.
sourceVariable String The original string.
subString String The string to be replaced.
replacementString String The replacement string.

Notes

The ReplaceAll function replaces all occurrences of subString in sourceString with replacementString. ReplaceAll is case-insensitive.

If replacementString is an empty string (""), the ReplaceAll function deletes every occurrence of the subString in the sourceString.

If subString is an empty string (""), the ReplaceAll function returns an unchanged copy of the sourceString.

Sample Code

Below are some examples that show the results of the ReplaceAll function

Var result As String
Var source As String = "xyxyxy"
result = source.ReplaceAll("x", "z") // returns "zyzyzy"

source = "the quick fox"
result = source.ReplaceAll(" ", "") // returns "Thequickfox"
result = source.ReplaceAll(" ", ", ") // returns "The, Quick, Fox"

See Also

Replace, ReplaceLineEndings functions.