日期:2014-05-17 浏览次数:20461 次
/** 给content的img添加a
* @param content
* @return
*/
private String updateContent(String content) {
StringBuffer result = new StringBuffer();
String temp = "";
int begin = content.toLowerCase().indexOf("<img");
while(begin != -1) {
result.append(content.substring(0, begin));
temp = content.substring(begin);
int imgSrcBegin = temp.toLowerCase().indexOf("src=") + 5;
String imgUrl = temp.substring(imgSrcBegin, imgSrcBegin + 50);
imgUrl = imgUrl.toLowerCase().replace("/s/", "/");
imgUrl = "<a rel=\"example_group\" href=\""+imgUrl+"\" >";
result.append(imgUrl);
int imgEnd = temp.toLowerCase().indexOf("/>") + 2;
String img = temp.substring(0, imgEnd);
result.append(img);
result.append("</a>");
content = temp.substring(imgEnd, temp.length());
begin = content.toLowerCase().indexOf("<img");
if(begin == -1)
result.append(content);
}
return result.toString();
}