Documentation/Calc Functions/REPLACEB/en

Function name:
REPLACEB

Category:
Text

Summary:
Replaces bytes in a text string with the bytes of a different text string.

Syntax:
REPLACEB(Text; Position; Length; New Text)

Returns:
Returns a text string that corresponds to the original text string but with the specified bytes replaced by those of the supplied new text string.

Arguments:
Text is a text string (in quotation marks), a number, or a reference to a cell containing one of those types, that is the original string containing bytes to be replaced.

Position is a positive integer, or a reference to a cell containing a positive integer, that is the position within Text of the first byte to be replaced.

Length is a non-negative integer, or a reference to a cell containing a non-negative integer, that is the number of bytes within Text to be replaced.

New Text is a text string (in quotation marks), a number, or a reference to a cell containing one of those types, that is the new string containing the replacement bytes. It is not necessary for the length of New Text to be the same as the value of Length. Set New Text to the empty string to delete rather than replace bytes in Text.
 * If either Position or Length is non-numeric, then REPLACEB reports a #VALUE! error.
 * If either Position or Length is a non-integer value, then REPLACEB truncates it to an integer value.
 * If Position is less than 1 or Length is less than 0, then REPLACEB reports an invalid argument error (Err:502).
 * If Position is greater than the length of Text, then REPLACEB reports an invalid argument error (Err:502).
 * If (Position + Length - 1) is greater than the length of Text, then REPLACEB reports an invalid argument error (Err:502).
 * If Length is equal to 0, no bytes are replaced. However, the bytes of New Text are inserted before the byte that is originally at the position given by Position.

Details specific to REPLACEB function
The formula:

is equivalent to:

If the specified number of bytes to be replaced would otherwise lead to replacing only one byte of a two-byte character, REPLACEB instead inserts a space character (Unicode U+0020) in the returned string. For example, the formula  returns  "x ｅｓｔ", having replaced the initial double-byte "ｔ" character (U+FF54) with a lowercase x (U+0078) followed by a space (U+0020). The formula  returns  " xｅｓｔ", having replaced the initial double-byte "ｔ" character (U+FF54) with a space (U+0020) followed by a lowercase x (U+0078).

You can pass the Text and New Text arguments as numbers but REPLACEB always returns text. If you intend to perform further calculations on a number that has been converted to text, you will need to convert it back to a number (for example, using either the VALUE function or the NUMBERVALUE function).

Examples:
Most of the following examples are similar to those used for the REPLACE function and demonstrate the consistent behavior of the two functions for single-byte character strings (SBCS).

The remaining examples demonstrate the behavior of REPLACEB for strings that include double-byte characters. These examples utilize the double-byte characters "中" (Unicode CJK Unified Ideograph-4E2D) and "国" (CJK Unified Ideograph-56FD).

Related LibreOffice functions:
FINDB

LEFTB

LENB

MIDB

REPLACE

RIGHTB

SEARCHB

ODF standard:
Section 6.7.6, part 2

Equivalent Excel functions:
REPLACEB