【发布时间】:2015-12-26 21:26:52
【问题描述】:
我想删除<script></script>tags 之间的内容。我正在使用 while 循环手动检查模式和iterating。但是,我在这一行得到StringOutOfBoundException:
String script = source.substring(startIndex,endIndex-startIndex);
下面是完整的方法:
public static String getHtmlWithoutScript(String source) {
String START_PATTERN = "<script>";
String END_PATTERN = " </script>";
while (source.contains(START_PATTERN)) {
int startIndex=source.lastIndexOf(START_PATTERN);
int endIndex=source.indexOf(END_PATTERN,startIndex);
String script=source.substring(startIndex,endIndex);
source.replace(script,"");
}
return source;
}
我在这里做错了吗?我得到endIndex=-1。谁能帮我确定我的代码为什么会出错。
【问题讨论】:
标签: java html html-parsing