# `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://coralogix.com/docs/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

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

```dataprime
(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:

```json
{
    "time_taken_str": "100μs"
}
```

Using `length` returns the number of characters:

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

This produces:

```json
{
    "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

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

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

### Example output

```json
{
    "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.
