String macros are specialized functions written in natural language that allow you to perform operations on strings. They handle all the logic involved in the process, from argument conversion to the final result and everything in between.
This is the summary of the available string macros for quick reference:
|Length||Counts 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.
This macro has the following syntax:
length of /*<value>*/
These are the supported parameters:
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