Forum Moderators: open

Message Too Old, No Replies

Searching substrings

         

asantos

4:37 pm on Oct 18, 2006 (gmt 0)

10+ Year Member



Hi

suppose i have this url string

http://example.com/zip/wp-websnapr-0.1.zip

i need my javascript to make a complete search on that string so that it recognizes if it ends up with
.zip
.exe
.rar
.swf

etc...
my initial approach was:

str = new String(nodes[i]);
result = str.lastIndexOf(".zip");
alert(result);

but its getting to dumb to code. i need something more dinamic. any ideas?

[edited by: jatar_k at 6:20 pm (utc) on Oct. 23, 2006]
[edit reason] examplified [/edit]

Trace

6:18 pm on Oct 23, 2006 (gmt 0)

10+ Year Member



Something like this maybe?

var myArray='http://example.com/zip/wp-websnapr-0.1.zip '.split(".");
alert(myArray[myArray.length-1])

Then just use a switch to compare it to whatever.

[edited by: jatar_k at 6:20 pm (utc) on Oct. 23, 2006]

Fotiman

6:27 pm on Oct 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Or just look at the last 4 characters to see if it's ".zip" or whatever.