DEV Community

Talha Munir 🇵🇸
Talha Munir 🇵🇸

Posted on

String functions in Age part 2

On our series of discussing functions in age.

In this article we will be discussing the second half of string functions in age. These functions can be used to manipulate the strings in some way. You can also visit the first part over here:
part1

lTrim:

The method returns the original string with removed white spaces.

Syntax:

lTrim(originalString)
Enter fullscreen mode Exit fullscreen mode
  • originalString is the string on which the operation will be performed.

Returns:

A String.

Sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN lTrim(' Talha ')
$$) as (trimmedString agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will trim the left most white spaces and will print "Talha " on the screen.

Trim:

The method returns the original string with all the white spaces removed either they be leading or trailing.

Syntax:

trim(originalString)
Enter fullscreen mode Exit fullscreen mode
  • originalString is the string on which the operation will be performed.

Returns:

A String.

Sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN trim(' Talha ')
$$) as (trimmedString agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will remove all the white spaces in the string and return the string "Talha".

ToLower:

The method returns the lowercase version of original string.

Syntax:

toLower(originalString)
Enter fullscreen mode Exit fullscreen mode
  • originalString is the string on which the operation will be performed.

Returns:

A String.

Sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN toLower('TALHA')
$$) as (lowerString agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will return the lowercase version of TALHA i.e. "talha"(Final string returned.)

ToUpper:

The method returns the original string in uppercase

Syntax:

toUpper(originalString)
Enter fullscreen mode Exit fullscreen mode
  • originalString is the string on which the operation will be performed.

Returns:

A String.

Sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN toUpper('talha')
$$) as (upperString agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will return the uppercase version of the string. i.e. "TALHA"

Reverse:

The method returns the reversed version of the string, i.e. the order of characters are reversed.

Syntax:

reverse(originalString)
Enter fullscreen mode Exit fullscreen mode
  • originalString is the string on which the operation will be performed.

Returns:

A String.

Sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN reverse("everytime")
$$) as (reversedString agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will reverse the order of characters in the string and will return "emityreve".

toString:

The method converts an integer, float or boolean value to a string value.

Syntax:

toString(An expression)
Enter fullscreen mode Exit fullscreen mode
  • Expression can be a integer, float or a boolean value or an expression that converts to a integer, float or a boolean.

Returns:

A String.

Sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN toString(99), toString('a string'), toString(true)
$$) as (floatToString agtype, str_to_str agtype, boolToString);
Enter fullscreen mode Exit fullscreen mode

The above query will return 3 strings "99", "a string", "true".

References:

You can view more on GitHub and documentation of Apache age by following these links:

  1. https://age.apache.org/age-manual/master/intro/overview.html
  2. https://github.com/apache/age
  3. https://dev.to/talhahahae/numeric-functions-in-apache-age-34ga
  4. https://dev.to/talhahahae/logarithmic-functions-1nbl
  5. https://age.apache.org/age-manual/master/functions/string_functions.html

Top comments (0)