This Commented CUE
demonstrates how to use the
built-in
function
len()
to calculate the lengths of different CUE types.
example.cue
package example
a: len([5, 4, 3, 2])
// Using len() on a string returns the number of
// bytes it contains, not the number of
// characters
// This input is of type bytes
b: len('😎abc123🥶')
// This input is of type string
b: len("😎abc123🥶")
TERMINAL
$ cue export
{
"a": 4,
"b": 14
}
Related content
- Don’t use the
len
function on a string, for the reason mentioned above. Constraining the length of a string demonstrates using functions from the built-instrings
package instead