Contact

Collabora Office REPLACEB: Replace weighted text spans safely

Text Intermediate Collabora Office Calc

Replace text using the pinned Collabora byte-style weighting, including partial-character spaces, zero-length insertion and strict range limits.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

Quick answer: with A1 containing A中B, =REPLACEB(A1;2;2;"X") independently predicts AXB. Position 2 begins 中, and Length 2 removes that complete two-unit character. Length counts the engine’s weighted text units, not ordinary characters or UTF-8 file bytes.

Syntax and indexing contract

=REPLACEB(Text; Position; Length; NewText)

Text is the original string. Position is the 1-based starting position; Length is how many weighted units to remove; NewText is the replacement string. All four arguments are required. Official REPLACEB help.

Use whole-number positions and lengths. Position must identify a valid position inside the existing weighted length, Length must be nonnegative, and the removal interval must not run beyond the end. NewText need not have the same length as the removed span. The function returns a new string; it does not edit the source cell in place.

The ByteLen helper assigns synthetic weights to UTF-16 units according to Unicode blocks. Selected CJK/Asian/fullwidth blocks weigh two; other units generally weigh one. Backslash and euro have Japanese-system-language exceptions. This is not a general file encoding or display-width API. Do not interpret the result as a byte-array edit of a UTF-8 file.

Worked example: replace one complete CJK character

Enter A中B in A1. Its weighted layout is A at position 1, 中 spanning positions 2–3, and B at position 4.

Use:

=REPLACEB(A1;2;2;"X")

The independent result is AXB. The prefix before the replacement is A, the two-unit 中 is removed, and the suffix is B. A complete-character replacement avoids the partial-slice behavior described below.

=REPLACEB(A1;4;1;"X") instead predicts A中X, replacing only the final ASCII character. The original A1 remains A中B in both examples. These calculations follow explicit weights and string slices, not an executed vendor workbook.

Advanced use: insert text or use a located position

=REPLACEB(A1;2;0;"X") predicts AX中B. Zero Length means insertion at an existing valid position; no original weighted units are removed.

To identify a substring dynamically, FINDB uses the same byte-style weighting. For this exact text, FINDB locates 中 at 2. A replacement must still use Length 2 to remove the entire character. A position alone does not tell you how many units the matched substring occupies.

When constructing identifiers or labels, perform the search and replacement against the same original string. If earlier processing changes the text, recompute the position. For ordinary character-oriented editing rather than a byte-style compatibility task, compare the separately documented REPLACE contract rather than assuming all scripts have width one.

Partial-character cuts insert spaces

The source constructs a left prefix and right suffix. If either boundary cuts through a two-unit character, the corresponding helper substitutes a space for that partial unit:

Formula Source-derived text, spaces significant
=REPLACEB("A中B";2;1;"X") AX B
=REPLACEB("A中B";3;1;"X") A XB

In the first case, the right suffix begins with a synthetic space. In the second, the left prefix ends with one. These spaces are not trimmed automatically and can alter later equality tests or identifiers. They are intentional outcomes of the pinned slicing helpers, not evidence that the original source text contained spaces.

A source formula using the left/right byte-style helpers therefore behaves differently from a Unicode character replacement when the requested span is misaligned. Prefer complete-character boundaries unless you specifically need this compatibility behavior.

Strict bounds and error paths

For the four-unit text A中B:

  • =REPLACEB("A中B";5;0;"X") follows internal IllegalArgument. Position after the end is rejected even though Length is zero; this is not an append operation.
  • =REPLACEB("A中B";2;4;"X") also fails because the removal span overruns the end. It is not silently shortened.
  • Position 0 or a negative Length is invalid.

The ScReplaceB evaluator checks these conditions before assembling prefix, replacement and suffix. The examples do not certify every supplementary Unicode character, locale-specific exception or localized UI error string.

REPLACE has a different indexing contract. Swapping the function name without checking positions and lengths can modify different text. File-format round trips and another spreadsheet product’s byte semantics require separate verification.

Product scope, compatibility and evidence

This guide covers the new Collabora Office desktop for Linux, using the Flathub source tag coda-26.04.4.3-1 and commit 81339d176148d0d5c81ff05d82540f58f8aaa117. The official desktop release notes and Linux package manifest identify that product/build. The package manifest is a dated observation from October 18, 2026, rather than an installed-binary check.

The 26.04 function help and exact evaluator source were inspected on October 18, 2026. Expected examples were independently calculated; no Collabora application was run. Expected scalar results were derived from the documented contracts, inspected source and independent calculations; native output formatting and error localization have not been tested. Classic, Online/CODE, other operating systems and file-format round trips require their own checks.

Availability here is established from the function-specific help and the mapped package source. Related functions may have different arguments or boundary rules. The first Collabora release introducing this function is not established by the reviewed sources. No cited retirement or deprecation notice was found. Unknown introduction dates do not imply that the function is deprecated. File-format round trips require separate verification.

  • FINDB: locate a substring using matching weighted positions
  • REPLACE: compare character-oriented replacement