To find within the next count characters : Scanner « File « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » File » Scanner 
11. 54. 10. To find within the next count characters
  1. String findWithinHorizon(Pattern pattern, int count)
  2. String findWithinHorizon (String pattern, int count)

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 MainClass {
  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!");
  }
}
77
import java.util.Scanner;

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

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

    if (sc.hasNext())
      System.out.println(sc.next());
    else
      System.out.println("Error!");
  }
}
77
import java.util.Scanner;

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

    sc.findWithinHorizon("IDs:",0);

    if (sc.hasNext())
      System.out.println(sc.next());
    else
      System.out.println("Error!");
  }
}
Name:
11. 54. Scanner
11. 54. 1. Using Scanner to receive user input
11. 54. 2. Using Scanner: the complement of Formatter
11. 54. 3. In general, to use Scanner, follow this procedure
11. 54. 4. Creating a Scanner: read from standard input: Scanner conin = new Scanner(System.in)
11. 54. 5. Creating a Scanner to read from a string
11. 54. 6. Using Scanner to read several different unknown types of data
11. 54. 7. Setting Delimiters for Scanner
11. 54. 8. To obtain the current delimiter pattern: Pattern delimiter( )
11. 54. 9. Searching for the specified pattern within the next line of text
11. 54. 10. To find within the next count characters
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.