Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Strings: SPLIT Function
     [next Lesson]  Strings: JOIN Function

Replace String Functions by Charles Carroll

The various string functions can be used interchangeably often. We will write the same script using SPLIT, REPLACE and JOIN to demonstrate all 3 functions and how they often are used for similar tasks. However, your programming situations may be especially suited for 1 out of 3 of the functions.

REPLACE(string,oldvalue,newvalue)
results in a string that has all occurences of oldvalue replaced with a newvalue.

The user can enter a state or multiple states. We write the program utilizing REPLACE to demonstrate how this  function can be used.

statereplace.asp

   filename=/learn/test/statereplace.asp

<Test Script Below>


<html><head>
<title>statereplace.asp</title>
</head><body bgcolor="#FFFFFF">
<form action="statereplacerespond.asp" method="post">
Enter State (or many states separated by <b>,<b><p>
<input NAME="states" size="40"><p>
<input type="submit" value="Get The Publishers!">
</form>
</body></html>

statereplacerespond.asp

   filename=/learn/test/statereplacerespond.asp

<Test Script Below>


<!--#include virtual="/learn/test/lib_dbtable.asp"-->
<html><head>
<title>statesrespond.asp</title></head>
<body>
<%
mySQL="select * from publishers " & whereclause
myDSN="DSN=student;uid=student;pwd=magic"

tempinput=request("states")

whereclause=" where state='" & tempinput
whereclause=replace(whereclause, ",","' OR state='")
whereclause=whereclause & "'"

mySQL=mySQL & whereclause
response.write mySQL
Call Query2Table(mySQL,myDSN)
%>
</body></html>

There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too. a $5 tip buys him lunch at McDonalds, a $20 tip buys his kid Hitoshi a new computer game, a $39 tip buys his daughter Michiko a few nice outfits. See our donor list.