-3

How to split escape character in this string?

enter image description here

already tried doing this

str = str.split('\\');

console.log(str);

this is the output

enter image description here

I want an output something like this

enter image description here

please help. thank you.

flyingpluto7
  • 1,079
  • 18
  • 20

2 Answers2

0

The escape character is consumed when the string literal is parsed so there are no \ characters in the string to replace.

It is too late to fix this programmatically. You need to edit the original source code to represent \ characters as \\.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

You can't create a string like this, you have to use the double backslash.

var str = "..\..\common\core\services\shared.service";
console.log(str); // "....commoncoreservicesshared.service"

// Correct way
var str = "..\\..\\common\\core\\services\\shared.service";
console.log(str); // "..\..\common\core\services\shared.service"
// Then use this:
str.replace(/\\/g, '/');
Navjot Ahuja
  • 1,141
  • 7
  • 10