代码: 全选
public class Replace {
public String rep(String html) {
String str = html;
try {
while (html.indexOf("<") > -1 && html.indexOf(">")>-1) {
int begin = 0, right = 0;
begin = html.indexOf("<"); // 起点
html=html.substring(begin);
right = html.indexOf(">");// 终点
String area = html.substring(0, right + 1); // 获得尖括号及之间的内容
html = html.substring(right + 1); // 右尖括号之后的内容
str = str.replace(area, "");
}
} catch (Exception e) {
System.out.println(e.toString());
}
return str;
}
public static void main(String[] args) {
Replace rep = new Replace();
System.out.println(rep.rep("home</a> > <a href=\"http://www.foot.com/shopping/index.php?osCsid=5108o0ib4hgq9r45rj1eeipl91\" class=\"headerNavigation\">shopping</a> >>"));
}
}