replace '\'n in javascript

前端 未结 8 764
情深已故
情深已故 2020-12-17 09:10

I\'m trying to do replace in JavaScript using:

r = \"I\\nam\\nhere\";
s = r.replace(\"\\n\",\" \");

But instead of giving me

相关标签:
8条回答
  • 2020-12-17 10:05

    Just use \\\n to replace it will work.

    r.replace("\\\n"," ");
    
    0 讨论(0)
  • 2020-12-17 10:06

    The solution from here worked perfect for me:

    r.replace(/=(\r\n|\n|\r)/gm," ");
    
    0 讨论(0)
提交回复
热议问题