Mega Code Archive

 
Categories / Java Tutorial / File
 

To find within the next count characters

String findWithinHorizon(Pattern pattern, int count) 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: