Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How do I select part of a string...

    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.
    Last edited by rabb17man; 12-11-2010 at 05:23 AM. Reason: question is resolved

  • #2
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    Code:
    var foo="/PACKAGES/test/run.html".split('PACKAGES/')[1].split('/run.html')[0];

  • Users who have thanked gizmo1650 for this post:

    rabb17man (12-11-2010)

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks gizmo1650 it is working now, much appreciated!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •