我写了下面的代码,它给了我以下输出:
if(bodytoUpper.contains(currentfield)){
int index = bodytoUpper.lastIndexOf(currentfield + "\n")//finds the last appearance of the field value
log.debug("Index try if Abfrage: ")
log.debug(index)
int nextindex = bodytoUpper.lastIndexOf(nextfield, index)//finds the index of the next field
log.debug("nextindex: ")
log.debug(nextindex)
value = currentbody.substring(index+currentfield.length(), nextindex);//sets the value to everything between the two indexes
log.debug("Rückgabewert: ")
log.debug(value)
}
该部分的输出是以下日志:
2017-12-22 11:24:52,853 DEBUG [acme.CreateSubtask]: Index try if Abfrage:
2017-12-22 11:24:52,853 DEBUG [acme.CreateSubtask]: 18
问题是,缺少一些日志(并且代码也不会被执行),但它不会输出错误消息。
我不知道你的脚本的目的,但我想这是在最后两次出现之间打印所有内容。
我认为问题是你正在向后搜索,所以nextindex
是在index
之前。所以你需要修改你的代码:
value = currentbody.substring(nextindex+currentfield.length(), index);