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]  Code w/all ASP Features. Quality, Re-usable Code
     [next Lesson]  Strings: SPLIT Function

String Functions by Charles Carroll

String functions are very useful for parsing data from ASCII files, formatting output in complex ways and parsing form input. The following scripts provides a sample of some crucial VBScript string functions in action. The string functions demonstrated are:

Instr(string,searchstring)
returns a numeric position where search string was found

Mid(string,start,length)
chops string at a start position for a fixed number of characters.

Mid(string,start)
results in a string that has all characters before startpos removed.

Trim(string)
removes all spaces from a string.

   filename=/learn/test/citystatezip.asp

<Test Script Below>


<html><head>
<title>citystatezip.asp</title>
</head><body bgcolor="#FFFFFF">
<Form action = "citystatezipRespond.asp" method="post">
Enter City <b>,</b> State Zip<p>
<Input NAME="CSZ" size ="40"><p>
<Input type="submit" value="Here is my Data!">
</form>
</body></html>

The user can enter a city, state and Zip, i.e.
Rockville, MD 20849
San Fransisco, CA xxxxx
Pike's Peak, CO xxxxx
and the program can use these functions to separate the data.

   filename=/learn/test/citystateziprespond.asp

<Test Script Below>


<html><head>
<title>citystateziprespond.asp</title>
</head><body>
<%
alldata=request("csz")
IF instr(alldata,",")=0 THEN%>
    You need a comma<br>,<br>between city and state!<p>
    <%response.end
END IF

findcomma=instr(alldata,",")
city=mid(alldata,1,findcomma-1)
leftover=trim(mid(alldata,findcomma+1))

findspace=instr(leftover," ")
state=mid(leftover,1,findspace)
leftover=mid(leftover,findspace+1)

zip=leftover

response.write "city=" & city & "<br>"
response.write "state=" & state & "<br>"
response.write "zip=" & zip & "<br>"


%>
</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.