LEN
Source: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgLen Last revised: 2024-04-03
Returns the length of an expression or data type.
Syntax
declare function Len ( byref expression as string ) as integer
declare function Len ( byref expression as zstring ) as integer
declare function Len ( byref expression as wstring ) as integer
declare operator Len ( byref expression as datatype ) as datatype
declare function Len ( datatype ) as integerUsage:
result = Len( expression )
result = Len( DataType )Parameters
- expression — An expression of any type.
- datatype — A DataType.
Return Value
Returns the size of an expression or DataType (including the data fields of a UDT) in bytes.
Description
Len returns the length of an expression or the size of a DataType, in bytes.
- If
expressionis of typeString,Wstring, orZstring, the length of the string in characters is returned. - If the expression is of a user-defined type, an
Operator Lencompatible with that data type is called. - Otherwise, the size of the expression's data type in bytes is returned.
In the second form (with a DataType argument):
- If
DataTypeisZstringorWstring, the size in bytes of one ASCII or Unicode character is returned. - If
DataTypeisString, the size of the string descriptor type is returned.
Note: If there is both a user-defined type and a variable visible with the same name in the current scope, the user-defined type takes precedence. To force Len to use the variable, wrap the argument in parentheses: Len((variable)).
Note: When used with array names, Len returns the length of the array's datatype, not the total number of elements. Prefer Len(Typeof(array)) for clarity.
The Len unary operator can be overloaded with user-defined types.
Examples
Print Len("hello world") ' returns "11"
Print Len(Integer) ' returns 4
Type xyz
a As Integer
b As Integer
End Type
Print Len(xyz) ' returns 8Version
- Before fbc 1.08.0,
Lenwas not returning the size of the data fields of a UDT.
Dialect Differences
Lenonly allows expressions in the-lang qbdialect.- Can be used with built-in types and user-defined types in
-lang fband-lang fblitedialects.
Differences from QB
- Can be used with built-in types and user-defined types in
-lang fband-lang fblitedialects.