How to remove all line breaks from a string

前端 未结 16 1469
轮回少年
轮回少年 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条回答
  •  Happy的楠姐
    2020-11-22 12:30

    If you want to remove all control characters, including CR and LF, you can use this:

    myString.replace(/[^\x20-\x7E]/gmi, "")
    

    It will remove all non-printable characters. This are all characters NOT within the ASCII HEX space 0x20-0x7E. Feel free to modify the HEX range as needed.

提交回复
热议问题