nathan schmoll's
aspdiscovery

back to main page

e-mail me








Using the "replace" function
Have you ever needed to modify a string? Even more, have you ever needed to replace a certain kind of character or certain set of words in a string with another character or set of words? Well, there is one very simple way to accomplish this!!

May I present to you . . . replace!

replace is a function that is not very well known, but can be VERY useful when making ASP scripts.

Let's say that you store different pages to a web site in a database and you don't want to type up your font tags every time you need them, you would just run the page content through the replace function.

<%
newpagecontent = _
replace(pagecontent,"<font>","<font _
face=""Verdana,Arial,Helvetica,Tahoma"" size=""2"">")
%>

The variable "newpagecontent" would then become the page content with all the <font> tags replaced with the font tag you want!

Here's another example. Let's say that you want to pass a web page address with variables in it's querystring along to another page via the querystring, you might want to replace all the question marks with something like "_qm_". This is what you would do in the page receiving the request with the question marks replaced with "_qm_":

<%
theoldurl = request.querystring("url")
theurl = replace(theoldurl,"_qm_","?")
%>

Hope you understand it now and if you don't -- read it again!

copyright © 2001, nathan schmoll. all rights reserved. questions? comments? suggestions? e-mail me!