Get substring after backslash in a string

HarshTimes
Tera Guru

hi
I have a string that contains a backslash.I want the substring after backslash. How can i get it?I tried substring function but its not working.PLease help me out.
example if the string is "first\last" I want to store 'last' in a variable.

14 REPLIES 14

adiddigi
Tera Guru



//say str contains the string
var lst = str.substr(str.indexOf('\\')+1);
gs.log(lst)


I checked this already,this is not working.


you tried with double slash or a single slash? if you paste the script exactly, it works.


using you script -
var lst = str.substr(str.indexOf('\\')+1);
gs.log(lst)

take one example-
var str = "first\last";
var lst = str.substr(str.indexOf('\\')+1);
gs.log(lst) ;
it will give the result 'firstlast',But the result should be 'last'.