Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace back slash (\) with forward slash (/) [duplicate]

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?

like image 310
manuel_k Avatar asked Mar 17 '17 10:03

manuel_k


People also ask

How do you change backward slash to forward slash?

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.

How do you change backslash to forward slash in Java?

In java, use this: str = str. replace("\\", "/");

What function could you use to replace slashes?

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 (\).

How do I change a backslash in typescript?

Use the String. replace() method to remove all backslashes from a string, e.g. const replaced = str. replace(/\\/g, ''); .


1 Answers

You have to escape to backslashes.

var path = "C:\\test1\\test2";
var path2 = path.replace(/\\/g, "/");
console.log(path2);
like image 130
Toto Avatar answered Sep 20 '22 14:09

Toto