[알고리즘] 이미지 추출하기 함수
이미지를 추출하길 원하시는 본문 내용(str)을 getImage를 이용하시면 해당 이미지의 src안의 값을 받을 수 있습니다.
String str = 이미지를 추출을 원하는 본문;
String imgStr = getImage(str);
이미지 추출 함수 |
public static String getImage(String str) { String ret=""; if ( str!=null) { String tmp=str.toLowerCase(); int lt=tmp.indexOf("<img"); if ( lt>-1) { int gt=tmp.indexOf(">",lt); if ( gt>-1) { str=str.substring(lt, gt); tmp=str.toLowerCase(); lt=tmp.indexOf("src="); if ( lt>-1) { gt=tmp.indexOf(".gif",lt); if ( gt<0 ) gt=tmp.indexOf(".jpg",lt); if ( gt<0 ) gt=tmp.indexOf(".png",lt); if ( gt<0 ) gt=tmp.indexOf(".bmp",lt); if ( gt>-1) { ret=str.substring(lt+4,gt+4); ret=ret.replaceAll("\"",""); } } } } } return ret; } |