java - what is the faster way to get the first img from URL string? -
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" > 
here quick code made. not tested should work. cut string array of sub strings "/" being cut. 1 of our sub strings has contain image, if not there no image file.
string[] src2=src.split("/"); string result="noting found !";  for(int i=0; < 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 @ first "space" , take "img.jpg" not "width"  if(!result.equals("noting found !")) system.out.println("we found image: "+result); 
Comments
Post a Comment