> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sdf.com/llms.txt
> Use this file to discover all available pages before exploring further.

# String Functions

## `chr`

Returns the Unicode code point n as a single character string.

*Examples:*

```sql examples.sql theme={null}
select chr(61) as value; -- value '='
```

*Supported Signatures*

```sql theme={null}
function chr(bigint) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#chr)

## `codepoint`

Returns the Unicode code point of the only character of `string`.

*Examples:*

```sql examples.sql theme={null}
SELECT codepoint('😊') AS value; -- value '128522'
```

*Supported Signatures*

```sql theme={null}
function codepoint(varchar) returns bigint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#codepoint)

## `concat`

Returns the concatenation of string1, string2, ..., stringN. This function provides the same functionality as the SQL-standard concatenation operator (||).

*Examples:*

```sql examples.sql theme={null}
select concat('hello ', 'world!') as value; -- value 'hello world!'
```

*Supported Signatures*

```sql theme={null}
function concat($3, array<$3>) returns array<$3>
function concat(array<$3>, ...) returns array<$3>
function concat(array<$3>, $3) returns array<$3>
function concat(varchar, varchar) returns varchar
function concat(varchar, ...) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#concat)

## `concat_ws`

Using the first array `string0` element as separator, returns the concatenation of all subsequent strings string1, string2, ... If \`string0\`\` is null, then the return value is null. Any null values provided in the arguments  after the separator are skipped.

*Examples:*

```sql examples.sql theme={null}
SELECT concat_ws('😊', 'hey', 'there', 'people') AS value; -- value 'hey😊there😊people'
```

*Supported Signatures*

```sql theme={null}
function concat_ws(varchar, array<varchar>) returns varchar
function concat_ws(varchar, ...) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#concat_ws)

## `length`

Returns the length of string in characters.

*Examples:*

```sql examples.sql theme={null}
select length('Hello World!') as value; -- value '12'
```

*Supported Signatures*

```sql theme={null}
function length(varchar) returns bigint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#length)

## `levenshtein_distance`

Returns the Levenshtein edit distance of string1 and string2, i.e. the minimum number of single-character edits (insertions, deletions or substitutions) needed to change string1 into string2.

*Supported Signatures*

```sql theme={null}
function levenshtein_distance(varchar, varchar) returns bigint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#levenshtein_distance)

## `lower`

Converts string to lowercase.

*Examples:*

```sql examples.sql theme={null}
select lower('Hello World!') as value; -- value 'hello world!'
```

*Supported Signatures*

```sql theme={null}
function lower(varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#lower)

## `lpad`

Left pads string to size characters with padstring. If size is less than the length of string, the result is truncated to size characters. size must not be negative and padstring must be non-empty.

*Examples:*

```sql examples.sql theme={null}
select lpad('😉', 5, '*') as value; -- value '****😉'
```

*Supported Signatures*

```sql theme={null}
function lpad(varchar, bigint, varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#lpad)

## `ltrim`

Removes leading whitespace from string.

*Examples:*

```sql examples.sql theme={null}
select ltrim('   😉') as value; -- value '😉'
```

*Supported Signatures*

```sql theme={null}
function ltrim(varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#ltrim)

## `replace`

Removes all instances of search from string.

*Examples:*

```sql examples.sql theme={null}
select replace('Hello There', 'There') as value; -- value 'Hello '
```

*Supported Signatures*

```sql theme={null}
function replace(varchar, varchar, varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#replace)

## `reverse`

Returns string with the characters in reverse order.

*Examples:*

```sql examples.sql theme={null}
select reverse('Hello There') as value; -- value 'ereht olleH'
```

*Supported Signatures*

```sql theme={null}
function reverse(array<$3>) returns array<$3>
function reverse(varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#reverse)

## `rpad`

Right pads string to size characters with padstring. If size is less than the length of string, the result is truncated to size characters. size must not be negative and padstring must be non-empty.

*Examples:*

```sql examples.sql theme={null}
select rpad('😉', 5, '*') as value; -- value '😉****'
```

*Supported Signatures*

```sql theme={null}
function rpad(varchar, bigint, varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#rpad)

## `rtrim`

Removes trailing whitespace from string.

*Examples:*

```sql examples.sql theme={null}
select rtrim('😉   ') as value; -- value '😉'
```

*Supported Signatures*

```sql theme={null}
function rtrim(varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#rtrim)

## `split`

Splits string on delimiter and returns an array.

*Examples:*

```sql examples.sql theme={null}
SELECT split('hello+world', '+') as value; -- value '[hello, world]'
```

*Supported Signatures*

```sql theme={null}
function split(varchar, varchar) returns array<varchar>
function split(varchar, varchar, bigint) returns array<varchar>
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#split)

## `split_part`

Splits string on delimiter and returns the field index. Field indexes start with 1. If the index is larger than the number of fields, then null is returned.

*Examples:*

```sql examples.sql theme={null}
SELECT split_part('hello world', 'world', 1) as value; -- value 'hello'
```

*Supported Signatures*

```sql theme={null}
function split_part(varchar, varchar, bigint) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#split_part)

## `starts_with`

Tests whether substring is a prefix of string.

*Examples:*

```sql examples.sql theme={null}
SELECT starts_with('hello world', 'world') -- value 'false'
SELECT starts_with('hello world', 'hello') ; -- value 'true'
```

*Supported Signatures*

```sql theme={null}
function starts_with(varchar, varchar) returns boolean
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#starts_with)

## `strpos`

Returns the starting position of the first instance of substring in string. Positions start with 1. If not found, 0 is returned.

*Examples:*

```sql examples.sql theme={null}
select strpos('Hello World', 'World') as value; -- value '7'
```

*Supported Signatures*

```sql theme={null}
function strpos(varchar, varchar) returns bigint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#strpos)

## `substr`

This is an alias for substring().

*Examples:*

```sql examples.sql theme={null}
select substr('Hello World', 6) as value; -- value ' World'
```

*Supported Signatures*

```sql theme={null}
function substr(varchar, bigint) returns varchar
function substr(varchar, bigint, bigint) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#substr)

## `substring`

Returns the rest of string from the starting position start. Positions start with 1. A negative starting position is interpreted as being relative to the end of the string.

*Examples:*

```sql examples.sql theme={null}
select substring('Hello World', 6) as value; -- value ' World'
```

*Supported Signatures*

```sql theme={null}
function substring(varchar, bigint) returns varchar
function substring(varchar, bigint, bigint) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#substring)

## `translate`

Returns the source string translated by replacing characters found in the from string with the corresponding characters in the to string.  If the from string contains duplicates, only the first is used.  If the source character does not exist in the from string, the source character will be copied without translation.  If the index of the matching character in the from string is beyond the length of the to string, the source character will be omitted from the resulting string.

*Examples:*

```sql examples.sql theme={null}
select translate('Hello World', 'Hell', 'N') as value; -- value 'No Word'
```

*Supported Signatures*

```sql theme={null}
function translate(varchar, varchar, varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#translate)

## `trim`

Removes any leading and/or trailing characters as specified up to and including string from source.

*Examples:*

```sql examples.sql theme={null}
select trim('  😉  ') as value; -- value '😉'
```

*Supported Signatures*

```sql theme={null}
function trim(varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#trim)

## `upper`

Converts string to uppercase.

*Examples:*

```sql examples.sql theme={null}
select upper('Hello World!') as value; -- value 'HELLO WORLD!'
```

*Supported Signatures*

```sql theme={null}
function upper(varchar) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/string.html#upper)
