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.
The output of the above code is here
my_string=" Welcome to Plus2net.com"
Response.Write "Before removing space the string =" & my_string
After removing space the string =" & my_string
Before removing space the string = Welcome to Plus2net.com
Check the space in both lines after the equal to mark ( = )
After removing space the string =Welcome to Plus2net.com
Same way we can remove spaces from the end of the string by using rtrim function.
Space from both sides can be removed by using trim() function.
Here is the code example for use of trim function
Be the first to post comment on this article :