Back to top
Documentation SurrealQL Functions String functions

String functions

These functions can be used when working with and manipulating text and string values.

Function Description
string::concat() Concatenates strings together
string::endsWith() Checks whether a string ends with another string
string::join() Joins strings together with a delimiter
string::length() Returns the length of a string
string::lowercase() Converts a string to lowercase
string::repeat() Repeats a string a number of times
string::replace() Replaces an occurence of a string with another string
string::reverse() Reverses a string
string::slice() Extracts and returns a section of a string
string::slug() Converts a string into human and URL-friendly string
string::split() Divides a string into an ordered list of substrings
string::startsWith() Checks whether a string starts with another string
string::trim() Removes whitespace from the start and end of a string
string::uppercase() Converts a string to uppercase
string::words() Splits a string into an array of separate words

string::concat

The string::concat function concatenates strings together.

string::concat(string...) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::concat('this', ' ', 'is', ' ', 'a', ' ', 'test');
"this is a test"

If any argument is not a string, then it will be cast to a string before the function is run:

SELECT * FROM string::concat(1, 2, 3, 4, 5);
"12345"

string::endsWith

The string::endsWith function checks whether a string ends with another string.

string::endsWith(string, string) -> boolean

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::endsWith('some test', 'test');
true

If any argument is not a string, then it will be cast to a string before the function is run:

SELECT * FROM string::endsWith(12345, '345');
true

string::join

The string::join function joins strings together with a delimiter.

string::join(string, string...) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::join(', ', 'a', 'list', 'of', 'items');
"a, list, of, items"

If any argument is not a string, then it will be cast to a string before the function is run:

SELECT * FROM string::join(', ', 1, 2, 3, 4, 5);
"1, 2, 3, 4, 5"

string::length

The string::length function returns the length of a given string.

string::length(string) -> number

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::length('this is a test');
14

If the argument is not a string, then the value will be cast to a string before the function is run:

SELECT * FROM string::length(12345);
5

string::lowercase

The string::lowercase function converts a string to lowercase.

string::lowercase(string) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::lowercase('THIS IS A TEST');
"this is a test"

If the argument is not a string, then the value will be cast to a string before the function is run:

SELECT * FROM string::lowercase(12345);
"12345"

string::repeat

The string::repeat function repeats a string a number of times.

string::repeat(string, number) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::repeat('test', 3);
"testtesttest"

If the first argument is not a string, then the value will be cast to a string before the function is run:

SELECT * FROM string::repeat(123, 3);
"123123123"

string::replace

The string::replace function replaces an occurence of a string with another string.

string::replace(string, string, string) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::replace('this is a test', 'a test', 'awesome');
"this is awesome"

If any argument is not a string, then it will be cast to a string before the function is run:

SELECT * FROM string::replace(12345, '12', '54');
"54345"

string::reverse

The string::reverse function reverses a string.

string::reverse(string) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::reverse('this is a test');
"test a is this"

If the argument is not a string, then the value will be cast to a string before the function is run:

SELECT * FROM string::reverse(12345);
"54321"

string::slice

The string::slice function extracts and returns a section of a string.

string::slice(string, number, number) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::slice('this is a test', 10, 4);
"test"

If the first argument is not a string, then the value will be cast to a string before the function is run:

SELECT * FROM string::slice(12345.00, 0, 5);
"12345"

string::slug

The string::slug function converts a string into a human and URL-friendly string.

string::slug(string) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::slug('SurrealDB has launched #database #awesome');
"surrealdb-has-launched-database-awesome"

If the argument is not a string, then the value will be cast to a string before the function is run:

SELECT * FROM string::slug(12345.00);
"12345-00"

string::split

The string::split function splits a string by a given delimiter.

string::split(string, string) -> array

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::split('this, is, a, list', ', ');
["this", "is", "a", "list"]

If any argument is not a string, then it will be cast to a string before the function is run:

SELECT * FROM string::split(12345.00, '.');
["12345", "00"]

string::startsWith

The string::startsWith function checks whether a string starts with another string.

string::startsWith(string, string) -> boolean

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::startsWith('some test', 'some');
true

If any argument is not a string, then it will be cast to a string before the function is run:

SELECT * FROM string::startsWith(12345, '123');
true

string::trim

The string::trim function removes whitespace from the start and end of a string.

string::trim(string) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::trim('    this is a test    ');
"this is a test"

If the argument is not a string, then the value will be cast to a string before the function is run:

SELECT * FROM string::trim(12345);
["12345"]

string::uppercase

The string::uppercase function converts a string to uppercase.

string::uppercase(string) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::uppercase('this is a test');
"THIS IS A TEST"

If the argument is not a string, then the value will be cast to a string before the function is run:

SELECT * FROM string::uppercase(12345);
"12345"

string::words

The string::words function splits a string into an array of separate words.

string::words(string) -> array

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM string::words('this is a test');
["this", "is", "a", "test"]

If the argument is not a string, then the value will be cast to a string before the function is run:

SELECT * FROM string::words(12345);
["12345"]