Length macro
Learn how to count the number of characters in a string.
This macro counts the number of characters in a given string, typically used for validation and manipulation purposes.
To find out the length of a string, this macro counts the number of Unicode characters, like we normally do when counting characters in a string. For example, the emoji "🙂" is represented by two bytes but is counted as a single character.
In the wild world of programming, the length of a string can mean different things, like the number of bytes. As a result, the length of characters with accents or emojis may be greater than one.
Syntax
This macro has the following syntax:
length of /*<value>*/
Parameters
These are the supported parameters:
- value
The string for which you want to determine the length.
Examples
Here is a practical example of how to get the length of a string:
length of "Hello, world! 👋" // 15
Note that if a value is not a string, CQL converts it to one whenever possible before determining its length:
length of 123 // 3