SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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)


Further readings
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
 
Scripts
PHP
JavaScript
All ASP Tutorials
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.