Method

ReplaceB


Warning

This item was deprecated in version 2019r2. Please use String.ReplaceBytes as a replacement.

Description

Replaces the first occurrence of a string with another string.

Usage

result=ReplaceB(sourceString, oldString, newString)

OR

result=stringVariable.ReplaceB(oldString, newString)

Part

Type

Description

result

String

A copy of sourceString with any changes made by the ReplaceB 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. ReplaceB is the byte version of String.Replace.

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

If oldString is an empty string (""), the ReplaceB 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 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 ReplaceB function:

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:

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.