JavaScript Question
This is I think a "pure" JavaScript question not DO really hence posting in Off-Topic.
It is related to this post:
Rename command, {alias} code and Double backslashes
Objective
In a JavaScript string variable I have reason to want to replace all instances of backslash
\
With TWO instances of (the same) backslash:
\
How do I do this in JavaScript in DO?
Problem
My problem is that the BackSlash is a Regex active Character
Control Method
If I want to replace the dash (-) with two dashes (--) that is easy.
I do this successfully in 2 ways as shown in the green and blue boxes below
- Green box = Use the String.replace method
- Blue box = Use the String.split method to create an array then the Array.join method to rejoin with the added character (dash in this case)
Broken Method
This is shown in the red box which as you can see tries the String.replace method.
It does not help that the backslash character is not a literal in a Javascript string either.
If this method did work then we should see the string presented with a set of single backslashes (as the second backslash would get eaten up acting as an escape character). But it does not.
Any ideas? Much appreciate any help......
PS just looked through the new feature summary for DO13..... very interesting!!!!