For example-
Input- C:\Sumit\dropbox\faces\Monika1\3b590ea4-610a-4c32-8486-bb06bbd23bc5.jpg
Output- \dropbox\faces\Monika1\3b590ea4-610a-4c32-8486-bb06bbd23bc5.jpg
i want to replace C:\Sumit
with nothing.
For example-
Input- C:\Sumit\dropbox\faces\Monika1\3b590ea4-610a-4c32-8486-bb06bbd23bc5.jpg
Output- \dropbox\faces\Monika1\3b590ea4-610a-4c32-8486-bb06bbd23bc5.jpg
i want to replace C:\Sumit
with nothing.
Yes:
var input = "C:\\Sumit\\dropbox\\faces\\Monika1\\3b590ea4-610a-4c32-8486-bb06bbd23bc5.jpg";
var output = input.replace("C:\\Sumit", "");
console.log("Input: " + input);
console.log("Output: " + output);
Notice the double backslash--this is because backslash is an escape character, so the first backslash tells the JavaScript interpreter an escape sequence is happening, and to look at the next character to find out what kind of escape sequence it is. The next character, the second backslash, tells it that the escape sequence produces a literal, single \
. In other words, the above "C:\\Sumit"
means C:\Sumit
when your code is interpreted. Try the "Run code snippet" button and you'll see that the input and output printed on the console have single slashes as they should.
If your input comes from, say, the value of a form element on a web page, then there's no need to do anything special with it: we only escape it here because we're specifying it as a string literal for testing purposes. But the call to input.replace()
should still have its backslashes escaped as shown, again because we're using a string literal there.
var str = "C:\\Sumit\\dropbox\\faces\\Monika1\\3b590ea4-610a-4c32-8486-bb06bbd23bc5.jpg";
var res = str.replace("C:\\Sumit", "");
The result of res will be: \dropbox\faces\Monika1\3b590ea4-610a-4c32-8486-bb06bbd23bc5.jpg