Determines the length of a character string, a string in a Variant or the size of a user defined type.
Len(a$ | vstr | udt)
a$ | : sexp |
udt | : user-defined type, udtvar |
vstr | : string in Variant |
Determines the number of characters contained within a string expression and returns this value.
For user defined types and their variables, Len(Type) and Len(var) return the length of the Types and the Type variable respectively.
OpenW # 1
Print Len("Hello world") //prints 11
Print Len(" Hello world ") //prints 13
Len returns the wrong value for a string in a Variant array: it returns the length of the Variant data type rather than the string - use VstrLen instead.
$Library "GfaWinX"
Global Variant x = "abcdefghijklmnopqrstuvwxyz"
Global z(3) As Variant
z(0) = "abcdefghijklmnopqrstuvwxyz"
z(1) = "abc"
Print x `Len(x) // Is okay because no array
Print z(0)`Len(z(0))`VStrLen(z(0)) // Shows 16, is 26 - VStrLen shows 26
Print z(1)`Len(z(1))`VStrLen(z(1)) // Shows 16, is 3 - VStrLen shows 3
Len acts as SizeOf for Variant arrays and will always return 16, the size of a Variant.
{Created by Sjouke Hamstra; Last updated: 06/03/2022 by James Gaite}