SHIP:Sail:length

From Serious Documentation
Jump to: navigation, search
Function Returns Introduced Description
length Integer v2.0 Returns the length in characters (not bytes) of a string.

See Also:

Prototype

Integer length(String s);

Parameters/Return Value

Parameter Data Type Description
s String String to measure
Return Integer number of characters in the string

Detailed Description

The length function returns the number of characters in a string. Strings are null terminated, and this terminating null is not included in the count. Since all strings in SHIP are UTF-8 encoded, a given character may be 1, 2, 3, or even more bytes in length. For example, the ™ symbol (Unicode-16 0x2123) requires 3 bytes in UTF-8 but is only considered a single character.

Examples

Example Result Notes
length("hello"); 5
length(""); 0
length("™"); 1 ™ is three bytes in UTF-8 but is only one character