-1

I want to replace all instance of particular string using javascript/jquery.

My source string is '\\n' and my desired output is '\n'.

this should happen at all instance with in a string.

shambhu yadav
  • 231
  • 2
  • 13
  • What is your input and expected output? – Durga Nov 13 '17 at 13:14
  • my input is "hii All, \\n I am sambo. \\n Thank you for listening." my main concern is to give break line in alert – shambhu yadav Nov 13 '17 at 13:16
  • `var s = "hii All, \\\n I am sambo. \\\n Thank you for listening.";alert(s.replace(/\\n/gi, '\n'))` add `\` in front of the `\n` to match your actual string - eg is that `\` `\` `n` or is it `\` `\n` – freedomn-m Nov 13 '17 at 13:19

1 Answers1

1

var str = "hii All, \\n I am sambo. \\n Thank you for listening.";
var res = str.replace(/\\n/gi, "\n");
console.log(str);

Use replace with regex.

Durga
  • 15,263
  • 2
  • 28
  • 52