- How can I replace characters at the very end of a string?
- Calculate the string length with LEN, add 1 to get the position after the last character, and use REPLACE with num_chars set to 0. This inserts new text without deleting anything, effectively appending it.
- Can REPLACE be used directly on numbers?
- REPLACE treats its first argument as text, so numeric values are coerced automatically. However, if you need specific number formatting, wrap the number in TEXT before applying REPLACE to preserve leading zeros or custom patterns.
- Why does REPLACE sometimes return the original text unchanged?
- When start_num is greater than the length of old_text, there are no characters to replace. In that case REPLACE simply returns the original string unchanged, which is useful for conditional logic.
- What is a good way to mask part of a ticket ID while keeping the rest visible?
- Use REPLACE to substitute the sensitive portion with asterisks or X's. For example, =REPLACE(A2,2,2,"XX") turns "1001" into "1XX1", hiding the middle characters while leaving the first and last digits readable.