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 by using ltrim().

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 "<br>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)

ASP Home

plus2net.com





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