Functions for working with strings

**Syntax**

```
isValidASCII(str)
```

**Aliases**: `isASCII`

**Arguments**

- None.

**Returned value**

**Examples**

**isValidASCII**

```
SELECT isValidASCII('hello') AS is_ascii, isValidASCII('你好') AS is_not_ascii
```

## isValidUTF8[​](#isValidUTF8 "Direct link to isValidUTF8")

Introduced in: v20.1.0

Checks if the set of bytes constitutes valid UTF-8-encoded text.

**Syntax**

```
isValidUTF8(s)
```

**Arguments**

- `s` — The string to check for UTF-8 encoded validity. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns `1`, if the set of bytes constitutes valid UTF-8-encoded text, otherwise `0`. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT isValidUTF8('\\xc3\\xb1') AS valid, isValidUTF8('\\xc3\\x28') AS invalid
```

```
┌─valid─┬─invalid─┐
│     1 │       0 │
└───────┴─────────┘
```

## jaroSimilarity[​](#jaroSimilarity "Direct link to jaroSimilarity")

Introduced in: v24.1.0

Calculates the [Jaro similarity](https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance#Jaro_similarity) between two byte strings.

**Syntax**

```
jaroSimilarity(s1, s2)
```

**Arguments**

- `s1` — First input string. [`String`](/docs/sql-reference/data-types/string)
- `s2` — Second input string. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the Jaro similarity between the two strings. [`Float64`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT jaroSimilarity('clickhouse', 'click')
```

```
┌─jaroSimilarity('clickhouse', 'click')─┐
│                    0.8333333333333333 │
└───────────────────────────────────────┘
```

## jaroWinklerSimilarity[​](#jaroWinklerSimilarity "Direct link to jaroWinklerSimilarity")

Introduced in: v24.1.0

Calculates the [Jaro-Winkler similarity](https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance) between two byte strings.

**Syntax**

```
jaroWinklerSimilarity(s1, s2)
```

**Arguments**

- `s1` — First input string. [`String`](/docs/sql-reference/data-types/string)
- `s2` — Second input string. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the Jaro-Winkler similarity between the two strings. [`Float64`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT jaroWinklerSimilarity('clickhouse', 'click')
```

```
┌─jaroWinklerSimilarity('clickhouse', 'click')─┐
│                           0.8999999999999999 │
└──────────────────────────────────────────────┘
```

## left[​](#left "Direct link to left")

Introduced in: v22.1.0

Returns a substring of string `s` with a specified `offset` starting from the left.

**Syntax**

```
left(s, offset)
```

**Arguments**

- `s` — The string to calculate a substring from. [`String`](/docs/sql-reference/data-types/string) or [`FixedString`](/docs/sql-reference/data-types/fixedstring)
- `offset` — The number of bytes of the offset. [`(U)Int*`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns:

- For positive `offset`, a substring of `s` with `offset` many bytes, starting from the left of the string.
- For negative `offset`, a substring of `s` with `length(s) - |offset|` bytes, starting from the left of the string.
- An empty string if `length` is `0`.
  [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Positive offset**

```
SELECT left('Hello World', 5)
```

```
Hello
```

**Negative offset**

```
SELECT left('Hello World', -6)
```

```
Hello
```

## leftPad[​](#leftPad "Direct link to leftPad")

Introduced in: v21.8.0

Pads a string from the left with spaces or with a specified string (multiple times, if needed) until the resulting string reaches the specified `length`.

**Syntax**

```
leftPad(string, length[, pad_string])
```

**Aliases**: `lpad`

**Arguments**

- `string` — Input string that should be padded. [`String`](/docs/sql-reference/data-types/string)
- `length` — The length of the resulting string. If the value is smaller than the input string length, then the input string is shortened to `length` characters. [`(U)Int*`](/docs/sql-reference/data-types/int-uint)
- `pad_string` — Optional. The string to pad the input string with. If not specified, then the input string is padded with spaces. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a left-padded string of the given length. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT leftPad('abc', 7, '*'), leftPad('def', 7)
```

```
┌─leftPad('abc', 7, '*')─┬─leftPad('def', 7)─┐
│ ****abc                │     def           │
└────────────────────────┴───────────────────┘
```

## leftPadUTF8[​](#leftPadUTF8 "Direct link to leftPadUTF8")

Introduced in: v21.8.0

Pads a UTF8 string from the left with spaces or a specified string (multiple times, if needed) until the resulting string reaches the given length.
Unlike [`leftPad`](#leftPad) which measures the string length in bytes, the string length is measured in code points.

**Syntax**

```
leftPadUTF8(string, length[, pad_string])
```

**Arguments**

- `string` — Input string that should be padded. [`String`](/docs/sql-reference/data-types/string)
- `length` — The length of the resulting string. If the value is smaller than the input string length, then the input string is shortened to `length` characters. [`(U)Int*`](/docs/sql-reference/data-types/int-uint)
- `pad_string` — Optional. The string to pad the input string with. If not specified, then the input string is padded with spaces. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a left-padded string of the given length. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT leftPadUTF8('абвг', 7, '*'), leftPadUTF8('дежз', 7)
```

```
┌─leftPadUTF8('абвг', 7, '*')─┬─leftPadUTF8('дежз', 7)─┐
│ ***абвг                     │    дежз                │
└─────────────────────────────┴────────────────────────┘
```

## leftUTF8[​](#leftUTF8 "Direct link to leftUTF8")

Introduced in: v22.1.0

Returns a substring of a UTF-8-encoded string `s` with a specified `offset` starting from the left.

**Syntax**

```
leftUTF8(s, offset)
```

**Arguments**

- `s` — The UTF-8 encoded string to calculate a substring from. [`String`](/docs/sql-reference/data-types/string) or [`FixedString`](/docs/sql-reference/data-types/fixedstring)
- `offset` — The number of bytes of the offset. [`(U)Int*`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns:

- For positive `offset`, a substring of `s` with `offset` many bytes, starting from the left of the string.\n"
- For negative `offset`, a substring of `s` with `length(s) - |offset|` bytes, starting from the left of the string.\n"
- An empty string if `length` is 0.
  [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Positive offset**

```
SELECT leftUTF8('Привет', 4)
```

```
Прив
```

**Negative offset**

```
SELECT leftUTF8('Привет', -4)
```

```
Пр
```

## lengthUTF8[​](#lengthUTF8 "Direct link to lengthUTF8")

Introduced in: v1.1.0

Returns the length of a string in Unicode code points rather than in bytes or characters.
It assumes that the string contains valid UTF-8 encoded text.
If this assumption is violated, no exception is thrown and the result is undefined.

**Syntax**

```
lengthUTF8(s)
```

**Aliases**: `CHARACTER_LENGTH`, `CHAR_LENGTH`

**Arguments**

- `s` — String containing valid UTF-8 encoded text. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Length of the string `s` in Unicode code points. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT lengthUTF8('Здравствуй, мир!')
```

```
┌─lengthUTF8('Здравствуй, мир!')─┐
│                             16 │
└────────────────────────────────┘
```

## lower[​](#lower "Direct link to lower")

Introduced in: v1.1.0

Converts an ASCII string to lowercase.

**Syntax**

```
lower(s)
```

**Aliases**: `lcase`

**Arguments**

- `s` — A string to convert to lowercase. [`String`](/docs/sql-reference/data-types/string)

**Returned value**