ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash





ASP Source Code:
<%
Dim strScriptName
Dim strInputText
' Read in the script name so I know where to
' point the form's action to.
strScriptName = Request.ServerVariables("URL")
' Read in the input from the text area.
strInputText = Request.Form("txtWordCount")
' Check for empty input and ignore it...
If strInputText = "" Then
	strInputText = "This is some text for the textarea!"
Else
	' Echo out the input:
	Response.Write "You entered:<br />" & vbCrLf
	Response.Write "<pre>"
	Response.Write Server.HTMLEncode(strInputText)
	Response.Write "</pre>" & vbCrLf
	' Print out the counts we got:
	Response.Write "<p>It contained <b>" _
		& GetWordCount(strInputText) _
		& "</b> words and <b>" _
		& GetCharCount(strInputText) _
		& "</b> characters.</p><br />" & vbCrLf
End If
' I wrapped these into functions so you can reuse them.
'**** Begin Functions ***********************************
Function GetWordCount(strInput)
	Dim strTemp
	' Deal with tabs and carriage returns
	' by replacing them with spaces.
	strTemp = Replace(strInput, vbTab, " ")
	strTemp = Replace(strTemp, vbCr, " ")
	strTemp = Replace(strTemp, vbLf, " ")
	' Remove leading and trailing spaces
	strTemp = Trim(strTemp)
	' Combine multiple spaces down to single ones
	Do While InStr(1, strTemp, "  ", 1) <> 0
		strTemp = Replace(strTemp, "  ", " ")
	Loop
	' Get a count by splitting the string into an array
	' and retreiving the number of elements in it.
	' I add one to deal with the 0 lower bound.
	GetWordCount = UBound(Split(strTemp, " ", -1, 1)) + 1
End Function ' GetWordCount
Function GetCharCount(strInput)
	GetCharCount = Len(strInput)
End Function ' GetCharCount
'**** End Functions *************************************
' Here's our form that we fill with the value they
' entered last time.
%>
<p>Enter some text:</p>
<form action="<%= strScriptName %>" method="post">
	<textarea name="txtWordCount" cols="40" rows="5"
	><%= Server.HTMLEncode(strInputText) %></textarea>
	<br />
	<input type="submit">
</form>

Back the the Sample Output

Back to the Sample Index


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers