SQL PHP HTML ASP JavaScript articles and free scripts to download

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


Google+

Further readings
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 Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer