`
plane
  • 浏览: 158244 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

替换html 中的图片

    博客分类:
  • java
阅读更多
public static void main(String[] args)
    {
        String temp = "<p><img height=\"600\" width=\"800\" alt=\"\" sRc=\"/adc_op/UserFiles/Image/Sunset.jpg\" /></p>"
            +"<p><ImG height=\"600\" width=\"800\" alt=\"\" sRc=\"/adc_op/UserFiles/Image/Sunset.jpg\" /></p>";
        System.out.println(replaceStr(temp,"","","http://10.30.3.236:8888"));
    }
	
	public static String replaceStr(String oriStr , String flag , String postionStr , String replaceStr) 
	{   
	    String tempStr = oriStr.toUpperCase();
	    
	    StringBuffer desStr = new StringBuffer();
	    int i = 0;
	    
	    while ( (i = tempStr.indexOf("<IMG")) != -1 )
	    {
	        i = tempStr.indexOf("SRC");
	        desStr.append(oriStr.substring(0,i+5));
	        
	        desStr.append(replaceStr);
	        tempStr = tempStr.substring(i+5);
	        oriStr = oriStr.substring(i+5);
	    }
	    desStr.append(oriStr);
	    
	    return desStr.toString();
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics