<div class="meta" robots="noindex">

</div>

Method

# Replace

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2022r1. Please use `String.Replace<string.replace>` as a replacement.

</div>

## Description

Replaces the first occurrence of a `string</api/data_types/string>` with another `string</api/data_types/string>`.

## Usage

*result*=*sourceVariable*.**Replace**(*oldString*, *newString*)

| Part           | Type                             | Description                                                                   |
|----------------|----------------------------------|-------------------------------------------------------------------------------|
| result         | `String</api/data_types/string>` | A copy of *sourceVariable* with any changes made by the **Replace** function. |
| sourceVariable | `String</api/data_types/string>` | The original string.                                                          |
| oldString      | `String</api/data_types/string>` | The characters to be replaced.                                                |
| newString      | `String</api/data_types/string>` | The replacement characters.                                                   |

## Notes

Replaces the first occurrence of *oldString* in *sourceString* with *newString*. <span class="title-ref">Replace</span> is case-insensitive.

If *newString* is an empty string (""), the <span class="title-ref">Replace</span> function deletes the first occurrence of the *oldString* in the *sourceString*.

If *oldString* is an empty string (""), the <span class="title-ref">Replace</span> function returns an unchanged copy of the *sourceString*.

## Sample code

Below are some examples that show the results of the <span class="title-ref">Replace</span> function:

``` xojo
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<string.replaceall>`, `ReplaceLineEndings<string.replacelineendings>` functions.
