In ASP, vbscript Left string function returns the substring of specified length starting from the left side of a string. You can use also the vbscript Len function to get the number of characters in the string that returns the string length. Vbscript len function enables you to get the position of last character and retrieve the substring starting from the left side of specified string upto the character position less than the length of the string.
Classic ASP VbScript String Functions Examples:
You can see the live samples and examples of Classic ASP VbScript String functions from the following links:
Syntax for ASP Vbscript Left String Function
Left(string, length)
Vbscript Left function accepts two parameters as shows in above syntax. You can use the vbscript Len function to specify the length parameter of Left string function.
-
string: this parameter accepts the string value or string type variable name.
-
length: this parameter accepts the number value to specify the length for the substring to be returned by the vbscript left function starting from the left side of a string specified in the string parameter.
Examples of ASP Vbscript Left String Function
Example 1:
<%
Dim myString
myString = "Vbscript Left String Function"
Response.Write(Left(myString, 15))
%>
Example 2:
<%
myString = "Vbscript Left"
Dim length
' here reverse vbscript for loop with step -1 is used to pass the decreasing length dynamically for length parameter of Left string function.
for length = Len(myString) to 1 step -1
Response.Write(Left(myString, length))
Response.Write("<br />")
next
%>
Output:
You can see the output of above discussed code from the following link:
String Left Function
Continue to next tutorial: ASP Vbscript Right String Function to learn how to get the substring from the right side of the specified string expression.