Welcome to my ASP Code Website

Replace ASP String Function



Replace is a commonly used ASP function that allows you to replace one character or characters in a string with another character or characters.

It takes in three parameters:

* The string variable to operate on
* A character or characters to look for
* A character or characters to replace that with

The original string variable is not altered.

There are MANY reasons to use Replace. One of the most common ones is in fixing email problems when people submit an email address to you. People are notorious for adding extra spaces to the beginning, end or even middle of their email address. Many mailers choke on those extra spaces. So to get rid of all spaces - replacing them with "nothing" - you would use:

RecEmail = Replace(RecEmail, " ", "")

Another common use of replace is to take in a comment that a user has typed in and format it for web reading. Users type in returns, or CHR(13) into their text. However, web browsers of course ignore hard returns so the user's text all mushes together. To change all of those returns with the web command <P> which is the paragraph break, you would use:

UserComment = Replace(UserComment, CHR(13), "<P>")

Now when you display UserComment, there are paragraph breaks to nicely separate the user's paragraphs.



Still stuck? Please be sure to Contact Lisa Shea - that's me - and I'm happy to lend a hand. I've been programming in ASP classic for many, many years and can help you get through your coding challenge quickly and easily!

To have an easy to use, easy to read reference on hand as you code, also check out my Intro to ASP Book which comes in both ebook and paperback format.

Thanks for stopping in to my page - and good luck!

ASP String Functions