Unable to replace backward slash "\" from a string

Arpita14
Kilo Explorer

Hi All, 

 

I am trying to split/replace a string that has backward slash"\" but unable to get the desired result.

var strVal = "Au\Group\This group"
var newStr = strVal.replace(/\\/g,"/"); [ or var newStr = strVal.split("\'");]

gs.info(newStr)

 

**Script completed in scope : AuGroupThis group

Is there any other  way to achieve this. Any advise/inputs will be of great help.

 

Thank you.

 

 

6 REPLIES 6

Hi Arpitha,

I have similar use case, Did you get any solution for this.

Thanks,

Sowmya

There's no solution because in JavaScript, a backslash "\" is an escape character.

As such, following code will treat "\G" and "\T" each as a single character and would  output 17. This is JavaScript language specification.

var strVal = "Au\Group\This group";
gs.info(strVal.length);

The problem is on setting the string variable to contain a single backslash. A single backslash should be replaced with double backslash before the value is set to a JavaScript variable.