Thread: searching
View Single Post
  #2 (permalink)  
Old 12-06-2007, 04:49 AM
staykovmarin staykovmarin is offline
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
You can always use a regex. If you dont know what a regex is, i strongly suggest you read Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)
Code:
// all the patterns that are going to have to be matched String [] array = {"bfg", "fgj", "cde", "efg", "ght"}; Matcher m; // scans trough each pattern for(int i = 0; i < array.length; i++) { // creates a new pattern for each element in the array Pattern p = Pattern.compile(array[i]); // attepts to match the created pattern to the specified string m = p.matcher("abcdefg"); // if the pattern matches: print if (m.find()) System.out.println(array[i] + " is contained"); }
Reply With Quote