views:

130

answers:

3

hi I have an textarea which anyone can enter text, where they can put line breaks inside the text area.

How can I remove the line breaks created by pressing the enter key? can either be in c# or javascript.

A: 

Try,

text.replace(/\s*/g," ")

This will collapse all contigious whitespace into a single space.

chuckj
/\s*/g will match any white space, not just line breaks, I think what is wanted is: text.replace(/[\n\r\f]/g, ' ') which will replace all new line, return, and form feed characters with a space.
Pullets Forever
I was replying to the title not the question I guess. The question only asks about line breaks but the title mentions whitespace.
chuckj
A: 

an alternative is to simply ban the use of the enter key in the textarea in the first place, which can be done with event handlers (onKeyPress, for example)

simonalexander2005
that can't be done since i'm keeping 2 kinds of data, the formatted data which they need to press enter and others, and all text data.
rob waminal
+1  A: 

Thanks to Scozzard here's the answer.. http://stackoverflow.com/questions/238002/replace-line-breaks-in-a-string-c

rob waminal