Function: Length
Length (
VALUE
)
Returns the length of a value. Behavior varies based on type.
Parameters
Parameter |
Type |
Description |
VALUE |
VALUE |
The input value (any type). |
Returns
VALUE(INTEGER) |
The length of the input value. |
What It Does
This function returns the length of the input value, which is different depending on the value type.
- If the value is numeric or boolean, this returns 1.
- If the value is a string, this returns the amount of characters in the string.
- If the value is a list, this returns the amount of elements in the list.
Example
Length Example
world
{
start()
{
textln("length(\"\") = "+length(""));
textln("length(\"apple\") = "+length("apple"));
textln("length(\"123456\") = "+length("123456"));
textln("length(\" \") = "+length(" "));
textln("length(true) = "+length(true));
textln("length(false) = "+length(false));
textln("length(0) = "+length(0));
local a;
a = [1, 2, 3, 4, 5];
textln("length("+a+") = "+length(a));
a = [[1, 2, 3], [4, 5, 6, 7, 8]];
textln("length("+a+") = "+length(a));
textln("length(a[0]) = "+length(a[0]));
textln("length(a[1]) = "+length(a[1]));
quit;
}
}
Example Result Table
Value | | Result |
BOOLEAN[false] | > LENGTH > | INTEGER[1] |
BOOLEAN[true] | > LENGTH > | INTEGER[1] |
FLOAT[Infinity] | > LENGTH > | INTEGER[1] |
FLOAT[-Infinity] | > LENGTH > | INTEGER[1] |
FLOAT[NaN] | > LENGTH > | INTEGER[1] |
INTEGER[0] | > LENGTH > | INTEGER[1] |
FLOAT[0.0] | > LENGTH > | INTEGER[1] |
INTEGER[10] | > LENGTH > | INTEGER[1] |
INTEGER[3] | > LENGTH > | INTEGER[1] |
FLOAT[10.0] | > LENGTH > | INTEGER[1] |
FLOAT[3.0] | > LENGTH > | INTEGER[1] |
FLOAT[10.5] | > LENGTH > | INTEGER[1] |
FLOAT[3.5] | > LENGTH > | INTEGER[1] |
INTEGER[-10] | > LENGTH > | INTEGER[1] |
INTEGER[-3] | > LENGTH > | INTEGER[1] |
FLOAT[-10.0] | > LENGTH > | INTEGER[1] |
FLOAT[-3.0] | > LENGTH > | INTEGER[1] |
FLOAT[-10.5] | > LENGTH > | INTEGER[1] |
FLOAT[-3.5] | > LENGTH > | INTEGER[1] |
STRING[] | > LENGTH > | INTEGER[0] |
STRING[ ] | > LENGTH > | INTEGER[1] |
STRING[0] | > LENGTH > | INTEGER[1] |
STRING[0.0] | > LENGTH > | INTEGER[3] |
STRING[10] | > LENGTH > | INTEGER[2] |
STRING[3] | > LENGTH > | INTEGER[1] |
STRING[10.0] | > LENGTH > | INTEGER[4] |
STRING[3.0] | > LENGTH > | INTEGER[3] |
STRING[10.5] | > LENGTH > | INTEGER[4] |
STRING[3.5] | > LENGTH > | INTEGER[3] |
STRING[-10] | > LENGTH > | INTEGER[3] |
STRING[-3] | > LENGTH > | INTEGER[2] |
STRING[-10.0] | > LENGTH > | INTEGER[5] |
STRING[-3.0] | > LENGTH > | INTEGER[4] |
STRING[-10.5] | > LENGTH > | INTEGER[5] |
STRING[-3.5] | > LENGTH > | INTEGER[4] |
STRING[apple] | > LENGTH > | INTEGER[5] |
STRING[banana] | > LENGTH > | INTEGER[6] |
STRING[NaN] | > LENGTH > | INTEGER[3] |
STRING[infinity] | > LENGTH > | INTEGER[8] |
LIST[[]] | > LENGTH > | INTEGER[0] |
LIST[[BOOLEAN[true], INTEGER[3], FLOAT[5.0], STRING[orange]]] | > LENGTH > | INTEGER[4] |