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, null will be returned.

  • If search is not found in original, original will 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) and split(original, null) both return null

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) and left(null, null) both return null

  • left(original, null) will raise an error.

  • If length is not a positive integer, an error is raised.

  • If length exceeds the size of original, original is returned.

Query:

SELECT *
FROM cypher('graph_name', $$
	RETURN left('Hello', 3)
$$) as (new_str agtype);

Result:

new_str
“Hel”
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:

  • start uses a zero-based index.

  • If length is omitted, the function returns the substring starting at the position given by start and extending to the end of original.

  • If original is null, null is returned.

  • If either start or length is null or a negative integer, an error is raised.

  • If start is 0, the substring will start at the beginning of original.

  • If length is 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) returns null

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) returns null

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) returns null

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) returns null

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) returns null

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) returns null.

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) returns null

  • If 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