Removing blank space before and after a string in ASP

We can remove blank spaces present before a string or after a string by using different functions in ASP. This is required in many string handling jobs and especially when user enters a data in a form. Some users may add space before or after entering their user id or password. They may not know or identify about the extra space they entered and the validation of id or password will fail because of extra space entered before or after entering the data.


We can remove blank space present before or after the string by using ltrim, rtrim and trim functions. Let us start with an example on how to remove space before the string.

Example

Dim my_string
my_string=" Welcome to Plus2net.com"
Response.Write "Before removing space the string =" & my_string
my_string=ltrim(my_string)
Response.Write "
After removing space the string =" & my_string

The output of the above code is here

Before removing space the string = Welcome to Plus2net.com
After removing space the string =Welcome to Plus2net.com

Check the space in both lines after the equal to mark ( = )

Same way we can remove spaces from the end of the string by using rtrim function.

my_string=rtrim(my_string)

Space from both sides can be removed by using trim() function.

Here is the code example for use of trim function

my_string=trim(my_string)


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