Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fstring%2Fbytelength.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fstring%2Fbytelength.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `byteLength`

## Description

Returns the number of bytes required to represent a UTF-8 encoded string.

## Syntax

Like many functions in DataPrime, `byteLength` supports<!-- --> [two notations](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

```
byteLength(value: string): number
```

```
(value: string).byteLength(): number
```

## Arguments

| Name    | Type     | Required | Description                          |
| ------- | -------- | -------- | ------------------------------------ |
| `value` | `string` | **true** | The string to measure in UTF-8 bytes |

## Example

**Compare character count vs. byte count for a UTF-8 encoded string**

Consider the following document:

```
{

    "time_taken_str": "100μs"

}
```

Using `length` returns the number of characters:

```
create len from time_taken_str.length()
```

This produces:

```
{

    "time_taken_str": "100μs",

    "len": 5

}
```

However, this does not reflect the true byte size. The character `μ` requires two bytes in UTF-8.

### Example query

* Function notation
* Method notation

```
create byte_len from byteLength(time_taken_str)
```

```
create byte_len from time_taken_str.byteLength()
```

### Example output

```
{

    "time_taken_str": "100μs",

    "byte_len": 6

}
```

The four ASCII characters (`1`, `0`, `0`, `s`) each take one byte, and the `μ` symbol takes two bytes, for a total of six.
