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 "
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 "
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 "
Length of this string = " & len(my_string)
Response.Write "
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


Be the first to post comment on this article :

plus2net.com




ASP functions to handle string
Adding two or more strings in ASP
Getting the size or length of the string by using len() function
Removing blank space before and after a string using trim function
Changing lower to upper or upper to lower case of text present inside a string
Reversing a string variable by using StrReverse function
Compare two strings in different ways by using StrComp function
Collecting parts from Left , right and middle areas of a string
Checking matching of a string inside another string using InStr function
Searching and replacing strings inside another string using Replace function
Creating arrays by splitting string using split() function
Joining elements of an array to create a string variable
Line Break by replacing text line break to html line break using Replace function

Post your comments , suggestion , error , requirements etc here .




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