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

</div>

Method

# ReplaceB

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

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `String.ReplaceBytes<string.replacebytes>` 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*=**ReplaceB**(*sourceString*, *oldString*, *newString*)

**OR**

*result*=*stringVariable*.**ReplaceB**(*oldString*, *newString*)

| Part           | Type                             | Description                                                                  |
|----------------|----------------------------------|------------------------------------------------------------------------------|
| result         | `String</api/data_types/string>` | A copy of *sourceString* with any changes made by the **ReplaceB** function. |
| sourceString   | `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.                                                  |
| stringVariable | `String</api/data_types/string>` | A `String</api/data_types/string>` variable containing the source string.    |

## Notes

Replaces the first occurrence of *oldString* in *sourceString* with *newString*. <span class="title-ref">ReplaceB</span> is the byte version of `String.Replace<string.replace>`.

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

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

ReplaceB is case-sensitive; it treats *sourceString* as a series of raw bytes. It should be used instead of `String.Replace<string.replace>` when the string represents a series of bytes or when your application will run in a one-byte character set (such as the US system) and you want case-sensitivity.

## Sample code

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

``` xojo
Var result As String
result = ReplaceB("The quick fox", "fox", "rabbit") ' returns "The quick rabbit"
result = ReplaceB("The quick fox", "f", "b") ' returns "The quick box"
result = ReplaceB("The quick fox", "quick ", "") ' returns "The fox"
```

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

Using the second syntax:

``` xojo
Var result, s As String
s = "The quick fox"
result = s.ReplaceB("fox", "rabbit") ' returns "The quick rabbit"
```

## Compatibility

All project types on all supported operating systems.

## See also

`String.ReplaceAllBytes<string.replaceallbytes>`, `String.Replace<string.replace>`, `String.ReplaceLineEndings<string.replacelineendings>` functions.
