Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Extract URL from string using AS2

Posted on 2007-07-22
3
Medium Priority
?
515 Views
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="http://www.mydomain.com/image123.jpg" /></td></tr></table>

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

http://www.mydomain.com/image123.jpg

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.
0
Comment
Question by:systemride
3 Comments
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 19541890
following function will work for you:

myString = '<table cellspacing="0"><tr><td>text content here blah blah... <img src="http://www.mydomain.com/image123.jpg" /></td></tr></table>';

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

}

trace(getImgUrlFromString(myString));


-------------------
Aneesh Chopra
-------------------
0
 
LVL 30

Accepted Solution

by:
third earned 1000 total points
ID: 19542787
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="http://www.mydomain.com/image123.jpg" /></td></tr></table>';

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

Author Comment

by:systemride
ID: 19544970
Works perfectly thanks.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

581 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