tags:

views:

41

answers:

2
  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
}

I know that somewhere before my data I need to get - i have a pattern -but I want to collect the data I need after the pattern - so maybe if I get the position of the pattern in the scanner I can substring in the scanner and collect what I need - but position is private - do I have a way to know it?

the data is different each time so i can not look for it directly

+1  A: 

how about

int startIndexOfMatch = sc.match().start();

?

please format your code as Code Sample.

ax
A: 

I tried that - thanks. But the scanner points to a string that is of length 727. But returns a value of 7024. What is the value returned? the memory or the offset inside the buffer?