Finding length of a string using len and lenB function in ASP

We can find out the length of a string by using len() function of VBScript in ASP. This way we can count the total number of letters or characters present in a string. This function takes the string variable or the string itself and returns the number of characters available within the string. Here is an example of uses of len function in finding out the length or size of a string.

Simple example of len() function
Dim my_string
my_string="Welcome to Plus2net.com"
Response.Write ( my_string )
Response.Write "<br>Length of this string = " & len(my_string)
Output of the above code is here
Welcome to Plus2net.com
Length of this string = 23
Now let us change the string a bit by adding some extra space before the word Welcome inside the string. The three line code is here .
my_string="   Welcome to Plus2net.com"
Response.Write ( my_string )
Response.Write "<br>Length of this string = " & len(my_string)


The output of the above code is here
Welcome to Plus2net.com
Length of this string = 26
You can see the extra space inside the string has not made any difference to the display of string as html code can't display extra space, but the difference can be seen in the length of the of the string. The three extra spaces we added at the beginning of the string have increased the length by 3 from 23 to 26. So extra spaces added any where within the string can add to the length of the string. We can also find out the bytes consumed by the string by using lenB() function. Here is an example.
my_string="Welcome to Plus2net.com"
Response.Write ( my_string )
Response.Write "<br>Length of this string = " & len(my_string)
Response.Write "<br>Number of bytes Required for this  string = " & lenB(my_string)
The output of this will also show the number of bytes required. Here in this case it will print this .
Welcome to Plus2net.com
Length of this string = 23
Number of bytes Required for this string = 46 

ASP Home

plus2net.com





We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer