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
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
Introduction to ASP Ebook Download this ebook to get everything you need to know about learning ASP - from a step by step tutorial to function lists, sample code, common errors and solutions, and much more! 101 pages. |
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map
Content copyright © 2023 by Lisa Shea. All rights reserved.
This content was written by Lisa Shea. If you wish to use this content in any manner, you need written permission. Contact Lisa Shea for details.