REPLACE
Replaces part of a text string by position.
REPLACE(old_text, start_num, num_chars, new_text) works by character index.
The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.
Syntax
=REPLACE(old_text, start_num, num_chars, new_text)
Arguments
| Argument | Type | Required | Default |
|---|---|---|---|
old_text | any | Required | — |
start_num | any | Required | — |
num_chars | any | Required | — |
new_text | any | Required | — |
Return type
Can return text.
Remarks
start_numis 1-based and must be at least1.num_charsmust be non-negative.- If start is beyond the end, the original text is returned unchanged.
- Non-text inputs are coerced to text.
Examples
Replace the final four ASCII characters by position.
Formula =REPLACE("East-2024",6,4,"2025")
Expected result East-2025
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Insert text without deleting source characters.
Formula =REPLACE("East-2024",6,0,"FY")
Expected result East-FY2024
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Delete the selected characters by replacing them with empty text.
Formula =REPLACE("East-2024",6,4,"")
Expected result East-
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
A start position of zero is invalid.
Formula =REPLACE("East-2024",0,4,"2025")
Expected result #VALUE!
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Replace middle segment
Formula =REPLACE("abcdef", 3, 2, "ZZ")
Expected result abZZef
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Insert at start
Formula =REPLACE("report", 1, 0, "Q1-")
Expected result Q1-report
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Related functions
FAQ
Does REPLACE match text patterns?
No. REPLACE is position-based and replaces by start_num and num_chars, not by searching old text.