Replace

From Xojo Documentation

(Redirected from String.Replace)
Method

Replaces the first occurrence of a string with another string.

Syntax

result=Replace(sourceString, oldString, newString)
OR
result=stringVariable.Replace(oldString, newString) Introduced 5.0

Part Type Description
result String A copy of sourceString with any changes made by the Replace function.
sourceString String The original string.
oldString String The characters to be replaced.
newString String The replacement characters.
stringVariable String A String variable containing the source string.

Notes

Replaces the first occurrence of oldString in sourceString with newString. Replace is case-insensitive.

If newString is an empty string (""), the Replace function deletes the first occurrence of the oldString in the sourceString.

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

Examples

Below are some examples that show the results of the Replace function:

Dim result As String
result = Replace("The quick fox", "fox", "rabbit") // returns "The quick rabbit"
result = Replace("The quick fox", "f", "b") // returns "The quick box"
result = Replace("The quick fox", "quick ", "") // returns "The fox"

Using the second syntax:

Dim result,s As String
s = "The quick fox"
result = s.Replace("fox", "rabbit") // returns "The quick rabbit"

See Also

ReplaceAll, ReplaceAllB, ReplaceB, ReplaceLineEndings functions.