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

# String Functions

> Text manipulation functions: UPPER, LOWER, CONCAT, SUBSTRING, TRIM, and more

## String functions

### UPPER

Converts a string to uppercase.

```sql theme={null}
SELECT UPPER('hello world') -- 'HELLO WORLD'
SELECT UPPER(name) AS uppercase_name FROM company_data."123"
```

### LOWER

Converts a string to lowercase.

```sql theme={null}
SELECT LOWER('HELLO WORLD') -- 'hello world'
SELECT LOWER(email) AS lowercase_email FROM company_data."123"
```

### TRIM

Removes leading and trailing whitespace.

```sql theme={null}
SELECT TRIM('  hello  ') -- 'hello'
SELECT TRIM(user_input) AS cleaned_input FROM company_data."123"
```

### LTRIM / RTRIM

Removes leading (LTRIM) or trailing (RTRIM) whitespace.

```sql theme={null}
SELECT LTRIM('  hello') -- 'hello'
SELECT RTRIM('hello  ') -- 'hello'
```

### LENGTH

Returns the number of characters in a string.

```sql theme={null}
SELECT LENGTH('hello') -- 5
SELECT LENGTH(description) AS desc_length FROM company_data."123"
```

### CONCAT

Concatenates multiple strings.

```sql theme={null}
SELECT CONCAT('Hello', ' ', 'World') -- 'Hello World'
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM company_data."123"
```

### CONCAT\_WS

Concatenates strings with a separator.

```sql theme={null}
SELECT CONCAT_WS('-', 'a', 'b', 'c') -- 'a-b-c'
SELECT CONCAT_WS(', ', city, state, country) AS location FROM company_data."123"
```

### SUBSTRING

Extracts a portion of a string.

```sql theme={null}
-- SUBSTRING(string, start_position, length)
SELECT SUBSTRING('hello world', 1, 5) -- 'hello'
SELECT SUBSTRING('hello world', 7, 5) -- 'world'
```

<Note>
  String positions are 1-based, not 0-based.
</Note>

### LEFT / RIGHT

Returns leftmost or rightmost characters.

```sql theme={null}
SELECT LEFT('hello', 2)  -- 'he'
SELECT RIGHT('hello', 2) -- 'lo'
```

### REPLACE

Replaces occurrences of a substring.

```sql theme={null}
SELECT REPLACE('hello', 'l', 'x') -- 'hexxo'
SELECT REPLACE(phone, '-', '') AS clean_phone FROM company_data."123"
```

### SPLIT

Splits a string into an array.

```sql theme={null}
SELECT SPLIT('a,b,c', ',') -- ['a', 'b', 'c']
SELECT SPLIT(tags, '|') AS tag_array FROM company_data."123"
```

### LPAD / RPAD

Pads a string to a specified length.

```sql theme={null}
SELECT LPAD('5', 3, '0')    -- '005'
SELECT RPAD('hello', 10, '.') -- 'hello.....'
```

### REGEXP\_EXTRACT

Extracts a substring matching a regular expression.

```sql theme={null}
SELECT REGEXP_EXTRACT('abc123def', '[0-9]+') -- '123'
SELECT REGEXP_EXTRACT(email, '@(.+)$') AS domain FROM company_data."123"
```

### LEVENSHTEIN

Calculates the edit distance between two strings.

```sql theme={null}
SELECT LEVENSHTEIN('hello', 'hallo') -- 1
SELECT LEVENSHTEIN(input_name, canonical_name) AS distance FROM company_data."123"
```

***

## Related content

<CardGroup cols={2}>
  <Card title="Date & Time Functions" icon="clock" href="/nql/functions/date-time-functions">
    Temporal operations
  </Card>

  <Card title="Conditional Functions" icon="code-branch" href="/nql/functions/conditional-functions">
    IF, COALESCE, NULLIF
  </Card>

  <Card title="All Functions" icon="function" href="/nql/functions/index">
    Browse all function categories
  </Card>

  <Card title="Data Types" icon="shapes" href="/nql/data-types">
    STRING type reference
  </Card>
</CardGroup>
