I have the string: \rnosapmdwq\salesforce\R3Q\OutputFiles\Archive
I'm getting a unrecognized escape sequence when I try to send this to a .NET web service.
I'm trying to replace all of the "\" with "|" to send it to the server.
I know I can use the replace method but that only replaces the first element. I think I need to use a regular expression to solve it.
Here's what I have so far:
Path = Path.replace("\\/g", "|");
This is wrong though.
To replace all backslashes in a string:Call the replaceAll() method, passing it a string containing two backslashes as the first parameter and the replacement string as the second. The replaceAll method will return a new string with all backslashes replaced by the provided replacement.
To replace all occurrences of a substring in a string by a new one, you can use the replace() or replaceAll() method: replace() : turn the substring into a regular expression and use the g flag. replaceAll() method is more straight forward.
You don't need to make a regex a string, and it helps having that first /
in there
Path = Path.replace(/\\/g, "|")
The correct syntax would be: Path = Path.replace(/\\/g, "|");
Working example at: http://jsfiddle.net/eDKej/.
Example (extra code for demonstration purposes only):
var Path = $("#path").text(); Path = Path.replace(/\\/g, "|"); $("#new-path").append(Path);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With