REPLACE Function

Replaces the first occurrence of one string with another string, and returns the string with the replacement made.

Category: String
Returned data type: String

Syntax

REPLACE(source, search-string, replace-string<, count>)

Required Arguments

source

specifies a string to search; this can be specified as string constant, field name, or expression

Note: If source is NULL, the function returns a NULL value.

search-string

specifies the text that is to be replaced; this can be specified as string constant, field name, or expression

replace-string

specifies a string that is to replace search-string; this can be specified as string constant, field name, or expression

Optional Argument

count

specifies an integer that represents how many replacements should be made; this can be specified as numeric constant, field name, or expression

Note: If count is omitted or set to zero, all occurrences will be replaced in the string.

Example

source_string =

     "It's a first! This is the first time I came in first place!"

search = "first"

replace = "second"

count = 2

result = replace(source_string, search, replace, count)

// outputs "It's a second! This is the second time I came in first place!"