Reputation: 1171
my string is "\upload\document\file.txt", i want to remove the "\upload" part in that string with jQuery. I try this one but it does not work:
var filePath = "\upload\document\file.txt";
filePath = filePath.replace('\upload', '');
console.log(filePath);
Upvotes: 0
Views: 194
Reputation: 337560
The issue is because the \u
at the start of the string is being interpreted as Unicode. Hence the error you see in the console.
To avoid this problem you need to use \\
to escape the single slashes in the string:
var filePath = "\\upload\\document\\file.txt";
filePath = filePath.replace('\\upload', '');
console.log(filePath);
Upvotes: 2
Reputation: 5796
You need to escape \
var filePath = "\\upload\\document\\file.txt";
filePath= filePath.replace('\\upload', '');
console.log(filePath)
Upvotes: 1