Solved

Delete carriage return in string

Posted on 2004-08-06
5
1,005 Views
Last Modified: 2007-12-19
I would like a javascript function which will replace a carriage return with an empty space.
Thanks
0
Comment
Question by:MichaelMullin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 25

Accepted Solution

by:
devic earned 50 total points
ID: 11739791
try this:
=======
<form>
<textarea name=t style=width:300px;height:300px></textarea>
      <input type=button value=OK onclick='this.form.t.value=this.form.t.value.replace(/\r\n/g,"")'>
</form>
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11739876
Hi

devic's should work. Of course, you can be more compliant by including all of his attributes in quotes, but it'll work. I'm thinking you want it to be for Unix, am I right? Well, if you only want to delete the \r, use:

this.form.t.value=this.form.t.value.replace(/\r/g,"") which is basically the same as devic's above

Regards,
Zyloch
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11742010
Small improvement of devic's code would be also to replace [\r\n]  for example on Linux\Unix\Mac browsers.

Like this:
<form>
<textarea name=t style=width:300px;height:300px></textarea>
     <input type=button value=OK onclick='this.form.t.value=this.form.t.value.replace(/[\r\n]/g,"")'>
</form>

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question