findWithinHorizon( )


String findWithinHorizon(Pattern pattern, int count) 
String findWithinHorizon(String pattern, int count)

findWithinHorizon( ) attempts to find an occurrence of the specified pattern within the next count characters. If successful, it returns the matching pattern. Otherwise, it returns null. If count is zero, then all input is searched until either a match is found or the end of input is encountered.


import java.util.Scanner;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner("Name: Tom Age: 28 ID: 77");

    sc.findWithinHorizon("ID:",100);

    if (sc.hasNext())
      System.out.println(sc.next());
    else
      System.out.println("Error!");
  }
}
Home 
  Java Book 
    Essential Classes  

Scanner:
  1. Scanner
  2. Setting Delimiters
  3. findInLine( )
  4. findWithinHorizon( )
  5. skip( )
  6. new Scanner(FileReader file)
  7. new Scanner(InputStream source)
  8. Scanner: hasNext()
  9. Scanner: hasNextBoolean()
  10. Scanner: hasNextDouble()
  11. Scanner: hasNextInt()
  12. Scanner: hasNextLine()
  13. Scanner: next()
  14. Scanner: nextBoolean()
  15. Scanner: nextDouble()
  16. Scanner: nextInt()
  17. Scanner: nextLine()