当我有以下包含
的文本文件时GET GET document
GET A B C
B------>C
基本上,我想检查文本文件是否包含/具有“GET”并执行进一步操作。如果它包含多个“GET”,那么需要获取它们并进行进一步的相同操作。我怎么知道我是否必须在文本文件中“获取”单词?
public Scanner getCircuitScanner(String circuitName) throws IOException
{
Scanner data = new Scanner(new File(circuitName));
while(data.hasNextLine())
{
String line = data.nextLine();
if(line.contains("GET"))
}
}
答案 0 :(得分:0)
取决于您对它们的处理方式,但只需获取“GET”关键字的起始位置即可:
int index = line.indexOf("GET");
while (index != -1) {
// Do something with "GET" at index here
index = line.indexOf("GET", index + 3);
}