View Full Version : Resolved How do I select part of a string...

12-11-2010, 06:09 AM
Hi all I am new here, hopefully someone can assist me with the following...

If I have ../PACKAGES/test/run.html stored in the variable myUrl and I want to extract whatever is between ../PACKAGES/ and /run.html how would I go about it?

I understand that in this instance I could use:

var actualUrl = myUrl.slice(12,16);

but the length of the string is dynamic, the only parts that stay the same are the start (../PACKAGES/) and end (/run.html).

I am new to java-script, so please be kind...any assistance would be much appreciated.

12-11-2010, 06:15 AM
var foo="/PACKAGES/test/run.html".split('PACKAGES/')[1].split('/run.html')[0];

12-11-2010, 06:21 AM
Thanks gizmo1650 it is working now, much appreciated! :thumbsup: