Click to See Complete Forum and Search --> : parse string


esthera
09-07-2003, 03:04 AM
I have a variable mystr which contains a string such as "C:\mydocuments\xxx.gif" I need to parse it and get the last 4 letters. (the .gif) How would I do this in Javascript?

AdamGundry
09-07-2003, 03:52 AM
You need to use String.substring (http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/string.html#1194665). Something like this:

var mystr = "C:\mydocuments\xxx.gif";
var substr = mystr.substring(mystr.length-5, mystr.length-1);

Adam

esthera
09-07-2003, 04:15 AM
thanks. i changed it a drop and it worked!