replace()
returns a string in which all occurrences of a specified string in the original string have been replaced by another (specified) string.
Syntax:replace(original, search, replace)
Returns: A String.
Arguments
Name | Description |
original | An expression that returns a string. |
search | An expression that specifies the string to be replaced in original . |
replace | An expression that specifies the replacement string. |
Example
RETURN replace("Hello, World!", "o", "a")
The value returned will be a string in which all occurrences of a specified string in the original string have been replaced by another (specified) string. In this example, all the occurrences of substring “o” will be replaced by replaced by another substring “a” in the original string. Hence the String returned will be “Hella, Warld!”.
Note- Since Strings are case sensitive, replacing substring “o” with “a”, for example, will replace all occurrences of “o” with “a”, but not not of “O”.
Considerations
- If any argument is
null
,null
will be returned. - If
search
is not found inoriginal
,original
will be returned.
Example
RETURN replace("Cypher Tutorials!", "e", "a")
Returns the following Result
replace("Cypher Tutorials!", "e", "a") |
"Cyphar Tutorials!" |
Example
RETURN replace("Cypher Tutorials!", "T", "Y")
Returns the following Result
replace("Cypher Tutorials!", "T", "Y") |
"Cypher Yutorials!" |
Example
RETURN replace("Cypher Tutorials!", "Cypher", "Neo4j")
Returns the following Result
replace("Cypher Tutorials!", "Cypher", "Neo4j") |
"Neo4j Tutorials!" |
Example
RETURN replace("Cypher Tutorials!", " ", "-")
Returns the following Result
replace("Cypher Tutorials!", " ", "-") |
"Cypher-Tutorials!" |
Example
RETURN replace("Cypher Tutorials!", "/", "-")
Returns the following Result
replace("Cypher Tutorials!", "/", "-") |
"Cypher Tutorials!" |
Note– If search
is not found in original
, original
will be returned.
Example
RETURN replace("Cypher Tutorials!", " ", null)
Returns the following Result
replace("Cypher Tutorials!", " ", null) |
null |
Note– If any argument is null
, null
will be returned.
Example
RETURN replace("Cypher Tutorials!", null, "-")
Returns the following Result
replace("Cypher Tutorials!", null, "-") |
null |
Note– If any argument is null
, null
will be returned.
Example
RETURN replace("Cypher Tutorials!", null, null)
Returns the following Result
replace("Cypher Tutorials!", null, null) |
null |
Note– If any argument is null
, null
will be returned.
Example
RETURN replace(null, " ", "-")
Returns the following Result
replace(null, " ", "-") |
null |
Note– If any argument is null
, null
will be returned.
Example
RETURN replace(null, null, null)
Returns the following Result
replace(null, null, null) |
null |
Note– If any argument is null
, null
will be returned.