private static String find(Scanner sc, String pattern) {
String Stoken;
while (( Stoken = sc.findInLine(pattern)) == null) {
if (sc.hasNextLine()) {
sc.nextLine();
} else {
return null;
}
}
return Stoken; // return string that match the pattern
}
我知道在我的数据之前的某个地方我需要获取 - 我有一个模式 - 但我想收集模式之后我需要的数据 - 所以也许如果我获得扫描仪中模式的位置,我可以在其中进行子串扫描仪并收集我需要的东西 - 但位置是私有(private)的 - 我有办法知道吗?
每次的数据都不一样,所以无法直接查找
最佳答案
怎么样
int startIndexOfMatch = sc.match().start();
?
请将您的代码格式化为代码示例。
关于java - 找到后如何获取扫描仪中的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/680998/