-4

It must recognize both forms:

<img src='http://www.mysite.com/myimg.png' width="89px" >
<img alt="ciao" width="89px" src="http://www.mysite.com/myimg.png" >
Usi Usi
  • 2,967
  • 5
  • 38
  • 69

1 Answers1

1

Here is a quick code I made. Not tested but it should work. Basically we cut up the string into a array of sub strings with "/" being where we cut. So one of our sub strings has to contain the image, if not then there is no image file.

String[] src2=src.split("/");
String result="noting found !";

for(int i=0; i < src2.length; i++) {
   if( src2[i].contains("img") && (src2[i].contains(".png") || src2[i].contains(".jpg")/* more extensions */) ) { // add more extensions if needed
      result = src2[i];
      break;
   {
}

result = result.split(" ")[0]; //will cut at the first "space" and take only the "img.jpg" not the "width"

if(!result.equals("noting found !")) System.out.println("We found an image: "+result);
Void
  • 402
  • 3
  • 12
  • 1
    Did you mean src2.length ;) – Usi Usi Aug 23 '13 at 17:08
  • without the (). Anyway this doesn't work well... It prints all the – Usi Usi Aug 23 '13 at 17:16
  • Well the rest depends on the data you get. Before you edited your question, there where no img at the beginning nor any widths... just a little modification will be enough though. There fixed. ;) – Void Aug 26 '13 at 09:01