How do I replace all line breaks in a string with
elements?

前端 未结 13 2536
刺人心
刺人心 2020-11-22 02:00

How can I read the line break from a value with JavaScript and replace all the line breaks with
elements?

Example:

A variable passe

13条回答
  •  耶瑟儿~
    2020-11-22 02:35

    It will replace all new line with break

    str = str.replace(/\n/g, '
    ')

    If you want to replace all new line with single break line

    str = str.replace(/\n*\n/g, '
    ')

    Read more about Regex : https://dl.icewarp.com/online_help/203030104.htm this will help you everytime.

提交回复
热议问题