Author Topic: Trim ASP String Function  (Read 3622 times)

Offline admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 296
    • View Profile
Trim ASP String Function
« on: December 20, 2009, 03:03:03 PM »
Trim is a commonly used ASP function that allows you to quickly remove any extra spaces at the beginning or ending of a string. It takes in one parameter:

* The string variable to operate on

The original string variable is not altered.

This is pretty much a required thing to do to ANY field a user types in for you to use. Users are notorious for putting extra spaces at the beginning or end of their input.

Let's say your user puts in their name and you take this in as UserName. But say the user has poor typing skills and you now get:

UserName = " Lisa Shea "

with extra spaces. You would use

UserName = Trim(UserName)

To turn that into just "Lisa Shea" with no spaces. Note that it leaves any spaces WITHIN the string - between the Lisa and the Shea. It only removes extra spaces at the beginning or end.