Freigeben über


Strings.Len Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns an integer containing either the number of characters in a string or the nominal number of bytes required to store a variable.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

Syntax

'Declaration
Public Shared Function Len ( _
    Expression As String _
) As Integer
public static int Len(
    string Expression
)

Parameters

  • Expression
    Type: System.String
    Any valid String expression or variable name. If Expression is of type Object, the Len function returns the size as it will be written to the file by the FilePut function.

Return Value

Type: System.Int32
Returns an integer containing either the number of characters in a string or the nominal number of bytes required to store a variable.

Remarks

With user-defined types and Object variables, the Len function returns the size as it will be written to a 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 a file.

NoteNote:

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.

Examples

This example uses Len to return the number of characters in a string.

' Initializes variable.
Dim TestString As String = "Hello World"
' Returns 11.
Dim TestLen As Integer = Len(TestString)

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.