String.ReplaceBytes

From Xojo Documentation

Method

ReplaceBytes()

New in 2019r2

Supported for all project types and targets.

Replaces the first occurrence of a string with another string.

Syntax

result=ReplaceBytes(sourceString, oldString, newString)
OR
result=stringVariable.ReplaceBytes(oldString, newString)

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

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

If oldString is an empty string (""), the ReplaceBytes function returns an unchanged copy of sourceString.

ReplaceBytes 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 ReplaceBytes function:

Var result As String
result = ReplaceBytes("The quick fox", "fox", "rabbit") // returns "The quick rabbit"
result = ReplaceBytes("The quick fox", "f", "b") // returns "The quick box"
result = ReplaceBytes("The quick fox", "quick ", "") // returns "The fox"

Using the second syntax:

Var result, s As String
s = "The quick fox"
result = s.ReplaceBytes("fox", "rabbit") // returns "The quick rabbit"

See Also

ReplaceAll, String.ReplaceAllBytes, Replace, ReplaceLineEndings functions.