2

Possible Duplicate:
Replace Line Breaks in a String C#

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.

Community
  • 1
  • 1
rob waminal
  • 18,117
  • 17
  • 50
  • 64
  • 1
    Could the answer to this question be helpful? - http://stackoverflow.com/questions/238002/replace-line-breaks-in-a-string-c – Scott Jul 15 '10 at 04:04
  • @Scozzard, that's just what I need, thanks. i think I didn't search too much in SO :) – rob waminal Jul 15 '10 at 05:08

2 Answers2

2

Try,

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

This will collapse all contigious whitespace into a single space.

chuckj
  • 27,773
  • 7
  • 53
  • 49
  • 1
    /\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. – David W. Keith Jul 15 '10 at 05:36
  • 1
    I was replying to the title not the question I guess. The question only asks about line breaks but the title mentions whitespace. – chuckj Jul 17 '10 at 18:35
0

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
  • 4,338
  • 4
  • 48
  • 92
  • 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 Jul 15 '10 at 11:04