Skip to main content

strlen

strlen (str)

The strlen function returns the number of bytes in the string expression str.

strlen returns NaN if the str is NULL. A local string variable or a string field in a structure that has never been set is NULL. NULL is not the same as zero length. (A global string is never NULL.) You can use numtype to test if the result from strlen is NaN, or use the stringIsNull function.

Examples

String zeroLength = ""
String neverSet
Print strlen(zeroLength), strlen(neverSet)

// Test if a string is null
Variable len = strlen(neverSet) // NaN if neverSet is null
if (numtype(len) == 2) // strlen returned NaN?
Print "neverSet is null"
endif

See Also

stringIsNull, Characters Versus Bytes, Character-by-Character Operations