I need to replace this path: C:\test1\test2
into this:
C:/test1/test2
I am using jquery but it doesn't seem to work
var path = "C:\test1\test2";
var path2 = path.replace("\", "//");
How should it be done?
By default the <Leader> key is backslash, and <Bslash> is a way to refer to a backslash in a mapping, so by default these commands map \/ and \\ respectively. Press \/ to change every backslash to a forward slash, in the current line. Press \\ to change every forward slash to a backslash, in the current line.
In java, use this: str = str. replace("\\", "/");
A regular expression is used to replace all the forward slashes. As the forward slash (/) is special character in regular expressions, it has to be escaped with a backward slash (\).
Use the String. replace() method to remove all backslashes from a string, e.g. const replaced = str. replace(/\\/g, ''); .
You have to escape to backslashes.
var path = "C:\\test1\\test2";
var path2 = path.replace(/\\/g, "/");
console.log(path2);
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