{strlen:string}

Description

Returns the length of a string, the AA counterpart of PHP strlen. The result is the number of BYTES, not characters - so a multi-byte UTF-8 character (an accented letter, an em-dash, an emoji) counts as the 2, 3 or 4 bytes it occupies, not as one. Whitespace counts and the argument is NOT trimmed, so leading and trailing spaces add to the length. A missing or empty argument returns 0. Use it to test a field for emptiness, enforce a length limit, or drive a condition on content.

Parameters

string required default (empty)

The text whose byte length you want. It is taken literally and is not trimmed, so spaces and any other whitespace count. A field getter or a nested expression can supply the value; the result is always the number of bytes, not characters.

Examples

test{strlen:hello}
Expected5
Actual5
Counts the bytes in a literal string. The five ASCII letters of hello are five bytes.
test{strlen:}
Expected0
Actual0
A missing or empty argument returns 0. This is the basis for an empty-field test.
test{strlen: hi }
Expected6
Actual6
The argument is not trimmed, so the two leading and two trailing spaces are counted along with the two letters: six bytes in total.
virtual{strlen:café}
Expected5 (4 characters, 5 bytes)
Actual5
strlen counts bytes, not characters. The word cafe written with an e-acute is c, a, f and then the accented e, which UTF-8 stores as two bytes - so the byte length is 5 even though a reader sees 4 characters. Use mb-strlen-style counting only if you need character counts. (Marked illustrative because the accented input cannot be stored reliably in this docs field.)
test{math:{strlen:abcd}+{strlen:xyz}}
Expected7
Actual7
The numeric result drops straight into math and other calculations. Here four bytes plus three bytes is seven.
test{ifeq:{strlen:}:0:empty:has content}
Expectedempty
Actualempty
A real-world use: branch on whether a value has any content. When the length is 0 the field is empty. Replace the empty argument with a field getter to test a real field.