REPLACEB Function (LibreOffice Calc)
Replace fixed byte-counted spans in LibreOffice Calc. See complete and split-character replacements, zero-length insertion and bounds that differ from a free-form append.
Verification status: Eight ordinary formula examples were recalculated in LibreOfficeDev 26.8.0.0.alpha0 (2c87e51eeaa2b413ff4ae097b2705eea1995d8e5) using headless XLSX import and forced recalculation. Exact saved text/positions and both controls were checked. LibreOffice 26.8.1.1 was source-checked only; no stable-release or GUI execution is claimed. How formula examples are checked
Quick answer: =REPLACEB("ä¸å›½";1;2;"æ—¥") returned “日国” in the tested development build.
Availability and version history
- Introduced: Introduced in LibreOffice 6.0.
- Supported in: LibreOffice 26.8 Help and 26.8.1.1 registration; no retirement is established.
- Scope: Desktop Calc, English semicolon-separated formulas. The byte convention is not a file-encoding byte offset.
- Checked: October 14, 2026. Eight listed formulas were recalculated in LibreOfficeDev 26.8.0.0.alpha0 using headless XLSX import. Stable releases and 26.8.1.1 were not executed.
What REPLACEB returns
REPLACEB removes a specified byte-counted span and joins the remaining prefix, NewText and suffix. It selects by position and length, not by searching for a matching word. The byte-counting rules can turn incomplete two-unit character fragments into spaces. Function Help.
Syntax and arguments
REPLACEB(Text; Position; Length; NewText)
Text is the original string. Position is the one-based byte start of the replacement. Length is the number of byte-counting units removed. NewText is the inserted string and can have a different length from the removed span. Exactly four arguments are required.
Eight reproducible examples
The native column is from LibreOfficeDev 26.8.0.0.alpha0, build 2c87e51eeaa2b413ff4ae097b2705eea1995d8e5, using headless XLSX import and forced recalculation. Text is quoted to distinguish empty strings and spaces. Delimiting quotation marks are not returned characters.
| Formula | Independent reference | LibreOfficeDev result |
|---|---|---|
=REPLACEB("ä¸å›½";1;2;"æ—¥") |
"日国" |
"日国" |
=REPLACEB("ä¸å›½";2;1;"X") |
" X国" |
" X国" |
=REPLACEB("ä¸å›½";2;2;"X") |
" X " |
" X " |
=REPLACEB("Aä¸å›½B";2;4;"X") |
"AXB" |
"AXB" |
=REPLACEB("Aä¸å›½B";2;0;"X") |
"AXä¸å›½B" |
"AXä¸å›½B" |
=REPLACEB("abcdef";3;2;"XY") |
"abXYef" |
"abXYef" |
=REPLACEB("ä¸å›½";1;4;"") |
"" |
"" |
=REPLACEB("ä¸å›½";3;2;"ABC") |
"ä¸ABC" |
"ä¸ABC" |
Practical worksheet
In Aä¸å›½B, the Chinese part occupies byte positions 2–5. Replacing four units starting at 2 with X gives AXB. With the same start but a zero length, the result is AXä¸å›½B: X is inserted without removing the original Chinese text.
For an ASCII code abcdef, replacing two units from position 3 with XY gives abXYef. This is a positional edit; it does not replace every occurrence of cd elsewhere in the string.
Keep the original field beside the edited output when cleaning imported data. Validate the position against the same LENB-style convention used to determine the span. A position obtained from a character-counting search can target the wrong boundary in a mixed-width string.
Advanced interpretation and checks
The callback validates the byte length and constructs a left prefix ending just before Position, followed by NewText and a byte-aware right suffix. The inserted string is used as supplied; it is not forced to occupy the removed byte count.
For ä¸å›½ with start 2, length 1 and replacement X, the prefix retains only half of ä¸ and becomes one space; the suffix is 国. The result is " X国". With start 2 and length 2, both retained edges split a character, producing " X “. Those leading and trailing spaces are real text.
Replacing the whole four-unit string with empty text returns an empty string. Replacing 国 with ABC produces ä¸ABC, showing that the output length can grow. For the selected characters, the corresponding LENB values follow from the independently checked prefix and suffix rules.
A comment next to the implementation describes a similar expression using RIGHT, but the actual executable suffix call is lcl_RightB. The guide follows that byte-aware call rather than the shortened comment. This distinction is material when a suffix contains a two-unit character. Inspected implementation.
Boundaries and troubleshooting
The inspected guard requires Position from 1 through the existing byte length, Length at least zero, and the end of the removed span no later than the text end. Therefore the source does not describe an unrestricted append at LENB(Text)+1, even when Length is zero. Those rejected-input paths were not executed in this ordinary fixture.
A zero-length insertion at an existing valid position is different from replacing zero characters beyond the end. Do not infer character-based REPLACE’s edge behavior or another product’s implementation from the similar name.
The locale-sensitive byte classification and unsupported exotic-character coverage are the same considerations as for MIDB. None of these byte-position functions directly measures a file’s UTF-8 byte offsets.
Related functions
Official evidence and checking scope
- Function-specific Help
- Complete versioned callback
- English native-name registration
- Byte classification and left/right helpers
The exact saved formulas and text were reconciled, including ODF repeated-space elements. Three empty-text cases across the fixture retain their formulas and empty paragraphs without a serialized value-type attribute; they are recorded as empty formula results. The stale SUM cache refreshed to 3 and the uncached SUM returned 7. This is headless development-build evidence, not a stable-release or GUI test.