hi,
here is my program that can read through a txt file line by line to find one word named "friends". if any line contains of this word then get the line and check my precised friend's name is mentioned there or not ?

its working when my precised named only one, but what should i do if it will more than one ?

suppose, my txt file contains like this:

my childhood friends named Jassei and Kathy.
Abbey, Kathy and Borny were my school friends.
In college, Jami and Abbey were good friends.
Here in university, Jacky and Hatchi are my new friends.

and code:

String target="friends";
String reading=new String();
String findName="Kathy";

try{
FileReader fr = new FileReader ("C:/Java/Test1.txt");   
BufferedReader reader = new BufferedReader (fr);

while (reader.ready()){ 
reading=reader.readLine();
                                
if (reading.indexOf(target)!= -1 ){ 
String line = result.substring(0, result.indexOf(target));
                                        
if (line.indexOf(findName) !=-1) {
System.out.println("Name found in:"+ indexOf(findName));
}
}
}
}
catch(IOException ioe){}

my question is, at a time i want to search more friend names not only "kathy"..

if i use like this,
String[] findNames={"kathy", "Borny", "Jakcy"}
then what to do ??
or any idea pls ??

Ever heard of "for" loop?

for(int = 0; i < findNames.length; i++){
    if (line.indexOf(findName[i]) !=-1) {
        System.out.println("Name found in:"+ indexOf(findName));
    }
}

thanks...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.