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:

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:

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:

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:

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:

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:

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:

Considerations:

  • right(null, length) and right(null, null) both return null
  • right(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 right('hello', 3)
$$) as (new_str agtype);

Result:

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:

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:

rTrim

rTrim() returns the original string with trailing whitespace removed.

Syntax: rTrim(original)

Returns:

An agtype String.

Arguments:

Considerations:

  • rTrim(null) returns null

Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN rTrim(' hello ')
$$) as (trimmed_str agtype);

Result:

lTrim

lTrim() returns the original string with trailing whitespace removed.

Syntax: lTrim(original)

Returns:

A String.

Arguments:

Considerations:

  • lTrim(null) returns null

Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN lTrim(' hello ')
$$) as (trimmed_str agtype);

Result:

trim

trim() returns the original string with leading and trailing whitespace removed.

Syntax: trim(original)

Returns:

An agtype String.

Arguments:

Considerations:

  • trim(null) returns null

Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN trim(' hello ')
$$) as (trimmed_str agtype);

Result:

toLower

toLower() returns the original string in lowercase.

Syntax: toLower(original)

Returns:

An agtype String.

Arguments:

Considerations:

  • toLower(null) returns null

Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN toLower('HELLO')
$$) as (lower_str agtype);

Result:

toUpper

toUpper() returns the original string in lowercase.

Syntax: toUpper(original)

Returns:

An agtype String.

Arguments:

Considerations:

  • toUpper(null) returns null

Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN toUpper('hello')
$$) as (upper_str agtype);

Result:

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:

Considerations:

  • reverse(null) returns null.

Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN reverse("hello")
$$) as (upper_str agtype);

Result:

toString

toString() converts an integer, float or boolean value to a string.

Syntax:toString(expression)

Returns:

A String.

Arguments:

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: