codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  ASP/JScript - Replace Function  swspm at 06:00 on Sunday, August 31, 2003
 

Can anyone translate the following code (ASP/VBScript) to ASP/JScript for me? Thanks
<%
Dim Address
Address = Request.Form("Address")
Address = Replace(Address, vbCrLf, "<BR>")
Address = Replace(Address, " ", " ")
%>

  Re: ASP/JScript - Replace Function  Troy Wolf at 19:09 on Sunday, August 31, 2003
 

Here is some client-side javascript to demonstrate this technique. The secret is to use a regular expression to represent the carriage return/line feed:

rExp = /\r\n/g'

This line says to find a carriage return (\r) followed by a line feed (\n) and to find all occurances of this combination (g for globally).

Simply copy and paste this code as an html file, then run it. Enter your test text in the text box then click "Test". Try entering content with no line breaks, one line break, then multiple line breaks.
-----------------------------
<script language=javascript>
function Test() {
rExp = /\r\n/g;
myString = document.forms[0].elements[0].value;
alert(myString);
myString = myString.replace(rExp,"<br>");
alert(myString);
}
</script>
<form>
<textarea cols=40 rows=8></textarea>
<br>
<input type=button value="Test" onclick="Test()">
</form>
-----------------------------

Troy Wolf
http://www.ShinySolutions.com is the answer to your hosting and web development needs.
Troy Wolf: site expert
SnippetEdit Website Editor









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Print and print preview file on the website without using the File - Print on the IE
•  Table dynamique (datafld and title)
•  reading xml embedded in HTML with JavaScript.
•  how to convert wav file to text file
•  html code running php function
•  Re: NEWBIE in need of help.
•  Converting a Long to Date time
•  How do I pass javascript cart variables to asp email body?
•  How do I pass javascript cart variables to asp email body?


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009