Visual Basic Language Reference  

Left Function

Returns a string containing a specified number of characters from the left side of a string.

Public Shared Function Left( _
   ByVal Str As String, _
   ByVal Length As Integer _
) As String

Parameters

Str
Required. String expression from which the leftmost characters are returned.
Length
Required. Integer expression. Numeric expression indicating how many characters to return. If 0, a zero-length string ("") is returned. If greater than or equal to the number of characters in Str, the entire string is returned.

Exceptions/Errors

Exception type Error number Condition
ArgumentException 5 Length < 0.

Remarks

To determine the number of characters in Str, use the Len function. If used in a Windows Form, or any other class that has a Left property, you must fully qualify the function with Microsoft.VisualBasic.Left.

Note   The LeftB function in previous versions of Visual Basic returns a string in bytes 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 LeftB is no longer supported.

Example

This example demonstrates the use of the Left function to return a substring of a given String. In a class that has a Left property, it may be necessary to fully qualify the Left function.

Dim myString As String = "Hello World!"
Dim subString As String
subString = Microsoft.VisualBasic.Left(myString, 5)   ' Returns "Hello"

Requirements

Namespace: Microsoft.VisualBasic

Module: Strings

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

Right Function | Len Function | Mid Function | ArgumentException Class | Programming Element Support Changes Summary