How to remove all line breaks from a string

前端 未结 16 1456
轮回少年
轮回少年 2020-11-22 11:36

I have a text in a textarea and I read it out using the .value attribute.

Now I would like to remove all linebreaks (the character that is produced when you press

16条回答
  •  遥遥无期
    2020-11-22 12:13

    How you'd find a line break varies between operating system encodings. Windows would be \r\n, but Linux just uses \n and Apple uses \r.

    I found this in JavaScript line breaks:

    someText = someText.replace(/(\r\n|\n|\r)/gm, "");
    

    That should remove all kinds of line breaks.

提交回复
热议问题