Contact

SUBSTITUTE Function (OpenOffice Calc)

Text Intermediate OpenOffice Calc

Learn the SUBSTITUTE function in Apache OpenOffice Calc: Substitutes new text for old text in a string.

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

Availability and version history

  • Introduced: Documented by Apache OpenOffice 4.1.16; original introduction not established.
  • Availability: Supported in Apache OpenOffice 4.1.16, verified against its function registry. This identifies a supported release, not a final working version.
  • Scope: Desktop Calc, using the English function name. Availability in other spreadsheet applications is separate.
  • Checked: 2026-10-14 — function reference; versioned support. Documentation/source check; not a new native test. Existing example-specific test claims below retain their stated scope.

SUBSTITUTE replaces literal matching text inside a string. Matching is case-sensitive. When the optional occurrence is omitted, the function replaces matches throughout; when supplied, it selects a particular occurrence. It is not the same operation as REPLACE, which uses a character position and removal length.

Syntax and arguments

=SUBSTITUTE(text; old_text; new_text; occurrence)
=SUBSTITUTE(text; old_text; new_text)

The first three arguments are required. old_text is the literal substring being found and new_text the inserted replacement. Optional occurrence is a positive one-based match number; omission requests all matches. The 4.1.16 source approximately floors an explicit occurrence and rejects effective values below 1 or above its internal bound. Use nonempty old_text for the examples and practical workflows below. English function names and semicolon argument separators are used here.

Reproducible examples

Formula Expected result
=SUBSTITUTE("blue car";"blue";"red") "red car"
=SUBSTITUTE("A-A-A";"A";"B") "B-B-B"
=SUBSTITUTE("A-A-A";"A";"B";2) "A-B-A"
=SUBSTITUTE("AbA";"A";"x") "xbx"
=SUBSTITUTE("abc";"x";"y") "abc"
=SUBSTITUTE("A-A";"-";"") "AA"

The first formula preserves the original guide’s worked example. Its historical comparable LibreOffice 25.2 check was not an OpenOffice test. New results are independently checked reference expectations; no fresh native or GUI test is claimed. Here "" denotes zero-length text.

Practical worksheet: standardize a known delimiter

Enter AB/001, CD/105 and EF/007 in A2:A4. In B2 enter =SUBSTITUTE(A2;"/";"-") and fill down. Expected strings are AB-001, CD-105 and EF-007. The field text and leading zeros stay intact.

Add AB/001/EU in A5. The same formula replaces both slashes, producing AB-001-EU. If only the first separator should change, =SUBSTITUTE(A5;"/";"-";1) returns AB-001/EU. Decide whether replacement applies to all matches or a particular occurrence before applying it to a whole dataset.

Advanced applications

Replace one selected match. =SUBSTITUTE("123123123";"3";"abc";2) returns 12312abc123. An occurrence larger than the available match count leaves the source unchanged; it does not append new text.

Account for overlapping selected matches in this source. The 4.1.16 implementation advances one character when skipping an occurrence, but advances past newly inserted text after replacement. Consequently its selected-occurrence scan can count overlapping matches: =SUBSTITUTE("aaaa";"aa";"X";2) has the source-derived expected result aXa. With occurrence omitted, =SUBSTITUTE("aaaa";"aa";"X") gives XX. Do not assume an imported workbook’s occurrence numbering matches another application for overlapping patterns. These are inspected-source expectations, not fresh native tests.

Count a one-character delimiter. With A-B-C in A2, =LEN(A2)-LEN(SUBSTITUTE(A2;"-";"")) returns 2. A multi-character pattern needs its own overlap and replacement interpretation; dividing a length difference by a pattern length is not a universal occurrence counter.

Errors, edge cases and troubleshooting

An explicit occurrence of zero is invalid; omitting the argument means all matches and is different from passing zero. Case-sensitive matching means replacing “A” does not replace “a”. The function uses literal string search, not SEARCH’s configurable regular-expression interpretation.

A missing old_text match leaves the input unchanged. This may look successful even when the data-cleaning assumption was wrong, so compare before and after if a replacement was required. Empty search-text behavior and every boundary involving an empty pattern are not certified here; validate a nonempty replacement key.

Replacing a short segment with longer text can expand the string to the application’s limit. Chained substitutions are applied in order and can create text that later substitutions match. Preserve the original values and specify the sequence. Numeric identifiers should be text when leading zeros matter. These ordinary ASCII cases do not establish Unicode normalization or grapheme-boundary behavior.

Documentation and verification

See the Apache OpenOffice SUBSTITUTE reference, 4.1.16 text-function help, and versioned interpreter. The official source snapshots were retrieved on October 13, 2026 and re-read for this guide; no new retrieval date is implied. Source inspection and reference calculations do not certify native encoding, locale or extreme-input behavior. First introduction and final functioning version remain unestablished; the lifecycle section identifies documented support.