Method

Replace


Warning

This item was deprecated in version 2022r1. Please use String.Replace as a replacement.

Description

Replaces the first occurrence of a string with another string.

Usage

result=sourceVariable.Replace(oldString, newString)

Part

Type

Description

result

String

A copy of sourceVariable with any changes made by the Replace function.

sourceVariable

String

The original string.

oldString

String

The characters to be replaced.

newString

String

The replacement characters.

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.

Sample code

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

Var result As String
Var source As String = "the quick fox"
result = source.Replace("fox", "rabbit") ' returns "The quick rabbit"
result = source.Replace("f", "b") ' returns "The quick box"
result = source.Replace("quick ", "") ' returns "The fox"

Compatibility

All project types on all supported operating systems.

See also

ReplaceAll, ReplaceLineEndings functions.