In Rails - is there a rails method to convert newlines to
?

后端 未结 8 1288
情书的邮戳
情书的邮戳 2020-12-04 11:30

Is there a Railsy way to convert \\n to
?

Currently, I\'m doing it like this:

mystring.gsub(/\\n/, \'
\')
8条回答
  •  鱼传尺愫
    2020-12-04 11:48

    You may make it more general by doing:

    mystring.gsub(/(?:\n\r?|\r\n?)/, '
    ')

    This way you would cover DOS, *NIX, Mac and accidental invalid line endings.

提交回复
热议问题