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, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
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:
Using length
returns the number of characters:
This produces:
However, this does not reflect the true byte size. The character μ
requires two bytes in UTF-8.
Output
The four ASCII characters (1
, 0
, 0
, s
) each take one byte, and the μ
symbol takes two bytes, for a total of six.
Theme
Light