Extract URL from string using AS2

Posted on 2007-07-22
Last Modified: 2012-06-22
I am trying to parse strings through a loop (in actionscript) that I get from an xml file. The string itself is actually HTML and I am trying to extract an image URL from that string. So the string would look something like so:

<table cellspacing="0"><tr><td>text content here blah blah... <img src="" /></td></tr></table>

...and from this string I would want to extract:

The thing is each string will be different and the text content before the image will be different lengths so i wouldn't be able to specify specific character numbers to find the start of the image url that I want to extract.

Can anyone provide help with this? Actionscript 2.0 please.
Question by:systemride
    LVL 34

    Expert Comment

    by:Aneesh Chopra
    following function will work for you:

    myString = '<table cellspacing="0"><tr><td>text content here blah blah... <img src="" /></td></tr></table>';

    function getImgUrlFromString(str):String
          var imgUrl = str.substring(str.indexOf('<img src="')+10,str.indexOf('.jpg"')+4);
          return imgUrl;



    Aneesh Chopra
    LVL 30

    Accepted Solution

    this may not be a perfect solution if the pattern on your codes will be different but this will give you the idea. try,

    str = '<table cellspacing="0"><tr><td>text content here blah blah... <img src="" /></td></tr></table>';

    var url = str.split('<img src=')[1].split('"')[1];
    LVL 2

    Author Comment

    Works perfectly thanks.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
    The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now