faqts : Computers : Programming : Languages : Asp : ASP/VBScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

80 of 83 people (96%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How can I replace the return characters in a text area with <BR>

Feb 20th, 2001 05:38
Scott Fleming, Nick Ashton, http://hawkwynd.com


Using the replace function in ASP, we can replace matches on a string 
input, or anything in a string.

Syntax: string=replace(StringToFix, StringToSearch, StringToReplace)


Here is an example of replacing the newline character of a user's 
comments, with the '<BR>' tags for displaying on a page.

--------------------------------------------------------------------
<html>
 <head>
    <title>Replace the vbcrlf with <BR></title>
 </head>
<body>

<%
 if Request.form("comment")<>"" Then
	strComent=replace(request.form("comment"), vbcrlf, "<br>")
	response.write strComent
	response.end
 Else

%>

Enter a comment, and click SEND to view it's formatted display<br>

<form action="default.asp" method="POST">

  <textarea name="comment" cols="50" rows="5" wrap="OFF"></textarea>
  <input type="Submit" value="send">

</form>

<% end if  %>

</body>
</html>

-----------------------------snip---------------------------------

You can also check for content in the form, and keep it clean:

myArray=array("damn","hell","badword","badword2","badword3")

    for each badword in myArray
        strComment=replace(strComment, badword, "< beep >")
    Next

This is just an example, of course, but shows the functionality of the 
replace function in real-world applications.



© 1999-2004 Synop Pty Ltd