Skip to main content
Previous sectionNext section

Len

Returns the number of characters in a string or the number of bytes required to store a variable.

Synopsis

Len(string | varname [,delimiter])

Arguments

string Any valid string expression.
varname Any valid variable name.
delimiter Optional — A valid string expression which demarcates separate substrings in the target string. If the delimiter is specified but is not part of the string, the Len function returns 1.

Description

The Len function returns the number of characters in a specified string or in the value of a specified variable. Numbers are converted to canonical form, with leading and trailing zeroes and plus signs removed. An empty string ("") returns a length of 0. An undefined variable returns a length of 0.

Examples

The following example uses the Len function to return the number of characters in a string:

Println Len("InterSystems")  ' Returns 12
Println Len(+0099.900)        ' Returns 4
Println Len("0099.900")      ' Returns 8
Println Len("")              ' Returns 0
Copy code to clipboard

The following example uses the Len function to return the number bytes required to store a variable.

x = 0099.900
y = Now
Println Len(x)        ' Returns 4
Println Len(y)        ' Returns 21:
                      ' mm/dd/yyyy 00:00:00PM
Println Len(z)        ' Returns 0
Copy code to clipboard

The following example uses the Len function to return the number of substrings delimited by the “/” character in a string:

Dim MyPieces
MyPieces = Len("09/02/1994", "/") 'MyPieces contains 3
Println MyPieces," pieces of the string"
Copy code to clipboard

See Also