Hi all,
I dont why my code is not detecting the matching words.
Firstly Im reading the words from a text file into an array.
Plz help me to make this correct.
This is my code.
import java.util.*;
import java.io.*;
public class TestRegex{
public static void main(String[] arg)
{
String s="ace";
int i=0;
/*if (s.matches(".*c.*e.*"))
System.out.println("ok");
for(char alphabet = 'A'; alphabet <= 'Z';alphabet++){
System.out.println(alphabet);
}
*/
String[] arrayWords=new String[120];
/* arrayWords[0]="apcple";
arrayWords[1]="appa";
arrayWords[2]="esjdchc";
arrayWords[3]="csksjce";
arrayWords[4]="ce";
arrayWords[5]="jazz";
arrayWords[6]="classic";
arrayWords[7]="sjdheiudc";
arrayWords[8]="no";
arrayWords[9]="yes";*/
try
{
FileInputStream fileStm = new FileInputStream("words.txt");
DataInputStream ins = new DataInputStream(fileStm);// Get the object of DataInputStream
BufferedReader br = new BufferedReader(new InputStreamReader(ins));
String line;
String delims = " ";//Delimeters
while ((line = br.readLine()) != null)//Read the file Line By Line
{
StringTokenizer st = new StringTokenizer(line, delims,false);//split the line into tokens according to provided delimas
//numTokens = st.countTokens();//count the number of tokens in the line
while(st.hasMoreTokens())//if there is a token go into the loop
{
String myToken=st.nextToken();
arrayWords[i]=myToken;
i++;
}
}
}catch (IOException io)
{
System.out.println("IO exception");
}
System.out.println("size : "+i);
String pattern=".*c.*e.*";
// System.out.println(arrayWords[10]);
String str=null;
for (int c=0;c<10;c++)
{
// System.out.println(arrayWords[c]);
str=(String)arrayWords[c];
if (str.matches(pattern))
{
System.out.println(arrayWords[c]);
}
}
}
}