Javascript substring from last backslash char

Viewed 28

This is probably a basic syntax question, but I am not able to find a syntax for a backslash character. Following and other syntaxes that I tried are not accepted for this char.

var fileNameSubstring = data.FileName.substring(data.FileName.lastIndexOf('\') + 1, data.FileName.length);
1 Answers

When defining a string in Javascript you can use the backslash (called escape character) to indicate special characters like new line \n.

To actually have a backslash in your string you should use double blackslash \\.

var fileNameSubstring = data.FileName.substring(data.FileName.lastIndexOf('\\') + 1, data.FileName.length);
Related