length ... (string function)

Prev Next

Function Names

length, vlength

Description

This function returns the number of characters in the string. New line symbols count as 1 character. If the value provided is not a string, then it will be converted to a string first.
Attention: For numerals and dates with available string context, the string will be used.



Vectorization: The function names beginning with the prefix v support vectorization in the 1st function parameter. Instead of providing a single value, you can provide a set or even a nested set which contain multiple values. The function will then process every value and its return value contains a corresponding set containing all results.
Note:For these functions, you need add the prefix letter 'v' in front of the function name. Otherwise the function recognizes a set and attempts to process sets and not strings. See length [set function] for the corresponding set function.

A simpler approach is to use {} behind the string, referred as length of strings. This simplified appraoch runs faster, but assumes a string value to be provided all times.

Call as: function

Restrictions

Indirect parameter passing is disabled
Vectorization is allowed in the 1st function parameter

Parameter count

1

Parameters

No.TypeDescription
1
input
valid types input string or value(s)

Attention: Numerals and dates are converted to strings prior to processing. If 1st parameter is a set:

  • If the function name starts with the v prefix, the vectorization applies. Provide multiple values in a (nested) set to process all of them at once.
  • Otherwise, please refer to length [set function] instead. Values of types other than string will be converted to strings first.

Return value

TypeDescription
numeral
set
Length value(s)

Number of characters. If vectorization has been applied, then the results are inside (nested) sets.

Examples

               echo( length( 007.0 ) );        // 5 characters (string context preserved)
               echo( length( 007.0 + 0 ) );    // 1 character (7) after a calculation
               echo( length( 1=1 ) );          // 4 characters (true)
               echo( length( Hello ) );        // 5 chracters
               echo( length( date(today)) );   // 10 characters: YYYY-MM-DD

Output

5
1
4
5
10
Try it yourself: Open LIB_Function_length.b4p in B4P_Examples.zip. Decompress before use.

See also

length [set function]
width
length of strings