ReplaceB

From Xojo Documentation

Method

Replaces the first occurrence of a string with another string.

Syntax

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

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 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 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.

Examples

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"

See Also

ReplaceAll, ReplaceAllB, Replace, ReplaceLineEndings functions.