ASP Is Fun

Learning ASP
Free Course
Basics
Functions
SQL Commands
Sample Code

Servers / Setup
Host Reviews
Server Setup
Error Tips

Contract ASP
Development

Intro to ASP



 


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.

ASP String Functions


ASP Main Page | ASP Ebooks | Free ASP Course | Contact Lisa
All content copyright © 2008 Minerva WebWorks LLC. All rights reserved.



Free Newsletter!

Ebooks
Intro to ASP
ASP SQL DB
Members
Shopping


Introduction to ASP

Romance Tips
Irish Romance
Italian Romance
French Romance

ASP Poll
How do you handle 500 errors?
I don't
Page does nothing
Displays error
Emails error