Returns an integer containing either the number of characters in a string or the number of bytes required to store a variable.
Public Shared Function Len( _
ByVal Expression As { Boolean | Byte | Char | Double | Integer | Long |
Object | Short | Single | String | DateTime | Decimal } _
) As Integer
With user-defined types and Object variables, the Len function returns the size as it will be written to the file. If an Object contains a String, it will return the length of the string. If an Object contains any other type, it will return the size of the object as it will be written to the file.
Note The Len function may not be able to determine the actual number of storage bytes required when used with variable-length strings in user-defined data types.
The LenB function in earlier versions of Visual Basic returns the number of bytes in a string rather than characters. It is used primarily for converting strings in double-byte character set (DBCS) applications. All Visual Basic .NET strings are in Unicode, and LenB is no longer supported.
This example uses Len to return the number of characters in a string.
Dim MyString As String Dim MyLen As Integer MyString = "Hello World" ' Initializes variable. MyLen =Len(MyString)' Returns 11.
Namespace: Microsoft.VisualBasic
Module: Strings
Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)
Data Type Summary | InStr Function |