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.
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))
%>
Output:
Vbscript Left S
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:
Vbscript Left
Vbscript Lef
Vbscript Le
Vbscript L
Vbscript
Vbscript
Vbscrip
Vbscri
Vbscr
Vbsc
Vbs
Vb
V