String Functions
replace
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:
An agtype 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 replacementstring. |
Considerations:
If any argument is
null,nullwill be returned.If search is not found in
original,originalwill be returned.
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN replace('hello', 'l', 'w')
$$) as (str_array agtype);
Result:
| new_str |
| “Hewwo” |
| 1 row(s) returned |
split
split() returns a list of strings resulting from the splitting of the original string around matches of the given delimiter.
Syntax: split(original, split_delimiter)
Returns:
An agtype list of agtype strings.
Arguments:
| Name | Description |
| original | An expression that returns a string. |
| split_delimiter | The string with which to split original. |
Considerations:
split(null, splitDelimiter)andsplit(original, null)both returnnull
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN split('one,two', ',')
$$) as (split_list agtype);
Result:
| split_list |
| [“one”,”two”] |
| 1 row(s) returned |
left
left() returns a string containing the specified number of leftmost characters of the original string.
Syntax: left(original, length)
Returns:
An agtype string.
Arguments:
| Name | Description |
| original | An expression that returns a string. |
| n | An expression that returns a positive integer. |
Considerations:
left(null, length)andleft(null, null)both returnnullleft(original, null)will raise an error.If
lengthis not a positive integer, an error is raised.If
lengthexceeds the size oforiginal,originalis returned.
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN left('Hello', 3)
$$) as (new_str agtype);
Result:
| new_str |
| “Hel” |
| 1 row(s) returned |
right
right() returns a string containing the specified number of rightmost characters of the original string.
Syntax: right(original, length)
Returns:
An agtype string.
Arguments:
| Name | Description |
| original | An expression that returns a string. |
| n | An expression that returns a positive integer. |
Considerations:
right(null, length)andright(null, null)both returnnullright(original, null)will raise an error.If
lengthis not a positive integer, an error is raised.If
lengthexceeds the size oforiginal,originalis returned.
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN right('hello', 3)
$$) as (new_str agtype);
Result:
| new_str |
| “llo” |
| 1 row(s) returned |
substring
substring() returns a substring of the original string, beginning with a 0-based index start and length.
Syntax: substring(original, start [, length])
Returns:
An agtype string.
Arguments:
| Name | Description |
| original | An expression that returns a string. |
| start | An expression denoting the position at which the substring will begin. |
| length | An optional expression that returns a positive integer, denoting how many characters of the original expression will be returned. |
Considerations:
startuses a zero-based index.If
lengthis omitted, the function returns the substring starting at the position given bystartand extending to the end oforiginal.If
originalisnull,nullis returned.If either
startorlengthisnullor a negative integer, an error is raised.If
startis 0, the substring will start at the beginning oforiginal.If
lengthis 0, the empty string will be returned.
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN substring('hello', 1, 3), substring('hello', 2)
$$) as (sub_str1 agtype, sub_str2 agtype);
Result:
| sub_str1 | sub_str2 |
| ‘ell’ | ‘llo’ |
| 1 row(s) returned | |
rTrim
rTrim() returns the original string with trailing whitespace removed.
Syntax: rTrim(original)
Returns:
An agtype string.
Arguments:
| Name | Description |
| original | An expression that returns a string |
Considerations:
rTrim(null)returnsnull
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN rTrim(' hello ')
$$) as (right_trimmed_str agtype);
Result:
| right_trimmed_str |
| " hello" |
| 1 row(s) returned |
lTrim
lTrim() returns the original string with leading whitespace removed.
Syntax: lTrim(original)
Returns:
An agtype string.
Arguments:
| Name | Description |
| original | An expression that returns a string |
Considerations:
lTrim(null)returnsnull
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN lTrim(' hello ')
$$) as (left_trimmed_str agtype);
Result:
| left_trimmed_str |
| “hello ” |
| 1 row(s) returned |
trim
trim() returns the original string with leading and trailing whitespace removed.
Syntax: trim(original)
Returns:
An agtype string.
Arguments:
| Name | Description |
| original | An expression that returns a string |
Considerations:
trim(null)returnsnull
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN trim(' hello ')
$$) as (trimmed_str agtype);
Result:
| trimmed_str |
| “hello” |
| 1 row(s) returned |
toLower
toLower() returns the original string in lowercase.
Syntax: toLower(original)
Returns:
An agtype string.
Arguments:
| Name | Description |
| original | An expression that returns a string |
Considerations:
toLower(null)returnsnull
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN toLower('HELLO')
$$) as (lower_str agtype);
Result:
| lower_str |
| “hello” |
| 1 row(s) returned |
toUpper
toUpper() returns the original string in uppercase.
Syntax: toUpper(original)
Returns:
An agtype string.
Arguments:
| Name | Description |
| original | An expression that returns a string |
Considerations:
toUpper(null)returnsnull
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN toUpper('hello')
$$) as (upper_str agtype);
Result:
upper_str
|
| “HELLO” |
| 1 row(s) returned |
reverse
reverse() returns a string in which the order of all characters in the original string have been reversed.
Syntax: reverse(original)
Returns:
An agtype string.
Arguments:
| Name | Description |
| original | An expression that returns a string |
Considerations:
reverse(null)returnsnull.
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN reverse("hello")
$$) as (reverse_str agtype);
Result:
| reverse_str |
| “olleh” |
| 1 row(s) returned |
toString
toString() converts an integer, float or boolean value to a string.
Syntax: toString(expression)
Returns:
A string.
Arguments:
| Name | Description |
| expression | An expression that returns a number, a boolean, or a string. |
Considerations:
toString(null)returnsnullIf expression is a string, it will be returned unchanged.
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN toString(11.5),toString('a string'), toString(true)
$$) as (float_to_str agtype, str_to_str agtype, bool_to_string);
Result:
| float_to_str | str_to_str | bool_to_str |
| "11.5" | "a string" | "true" |
| 1 row(s) returned | ||