PDA

View Full Version : lastIndexOf slash??



Uli
September 19th, 2004, 10:02 PM
Hello,

Im trying to use the lastIndexOf function to discover where the last "\" is located in my string... It seems to have a pb with the \ symbol..
I tried mystring.lastIndexOf('"\"') and every other possibleway, it always returns -1

Any ideas?

senocular
September 19th, 2004, 10:19 PM
use "\\" since it is used in combination with escape characers (like \n and \t), it, itself, has to be escaped

Uli
September 19th, 2004, 10:21 PM
Ok i've found a way...
heh = String.fromCharCode(92);
lastslashpos = myvar.lastIndexOf(heh);
That seems to work with the ascii code..

Thanks for your reply tho

amitgeorge
September 20th, 2004, 04:47 AM
senocular's ver is simpler ?

lastslashpos = myvar.lastIndexOf("\\");