Results 1 to 3 of 3
- 03-27-2010, 07:10 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
how to find more than one String with single command
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:
and code: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.
my question is, at a time i want to search more friend names not only "kathy"..Java 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"); } } } } catch(IOException ioe){}
if i use like this,
String[] findNames={"kathy", "Borny", "Jakcy"}
then what to do ??
or any idea pls ??what we are thinking, it might not be true
-
Loop through the array with a for-loop.
Also, if you indent your pasted code so that it's easier to read it will be easier for us to help you. Thanks in advance.
Oh, and you'll really want to avoid empty catches:
because how will you know if an error occurs, why it has occurred?Java Code:catch(IOException ioe){}
- 03-27-2010, 07:22 PM #3
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Similar Threads
-
find index of string in another string
By Sdannenberg3 in forum New To JavaReplies: 4Last Post: 03-04-2010, 10:14 AM -
Compiling/Running Project in Command Line: "Could not find main class" Error
By Yasemin Gokce in forum New To JavaReplies: 1Last Post: 06-30-2009, 02:32 PM -
Find a number from a string
By florentp in forum New To JavaReplies: 2Last Post: 03-20-2009, 09:01 PM -
Splitting single string into array elements
By phil128 in forum New To JavaReplies: 11Last Post: 01-12-2009, 11:51 AM -
Find and replace ( in a String
By hamish10101 in forum New To JavaReplies: 6Last Post: 01-17-2008, 05:51 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks