Name
Left Function
Class
Microsoft.VisualBasic.Strings
Syntax
Left(str, length
)
-
str
Use: Required
Data Type: String
The string to be processed
-
length
Use: Required
Data Type: Long
The number of characters to return from the left of the string
Return Value
String
Description
Returns a string containing the leftmost
length
characters of
str
Rules at a Glance
If
length
is 0, a zero-length string (“”) is returned.If
length
is greater than the length ofstr
,str
is returned.If
string
isNothing
,Left
returnsNothing
.
Programming Tips and Gotchas
Use the
Len
function to determine the overall length ofstr
.The
Left
function corresponds to the BCL System.String class’ Substring method. For example, the following two assignments to thesCity
variable are functionally identical:Dim sCity As String Dim sLocation As String = "New York, New York" sCity = Left(sLocation, 8) sCity = sLocation.Substring(0, 8)
Note that the Substring method uses a zero-based index to determine the starting position of the substring.
See Also
Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.