REPLACE

REPLACE replaces a segment of a string with another string.

Function category: Text

Syntax

REPLACE(arg1, arg2, arg3, arg4)

Arguments

Description

arg1

String to be segmented.

arg2

Position in the string at which to begin slicing.

arg3

Number of characters to slice from the string.

arg4

String to replace the substring delineated by arg2 and arg3.

arg2 is inclusive, meaning the character at the specified position will be included in the segment.

Example

Example 1: Replace digits with another string

Let's say we're given a response with an id:

{
"data":{
"ids":{
"id_1": "1anb4amca051"
}
}
}

If we replace the first four digits of the id with our own string, we can do so using REPLACE:

REPLACE(data.ids.id_1, 1, 4, "custom-id-")

This returns the following:

"custom-id-4amca051"