Board index » jbuilder » Line number of a specific "word" appears

Line number of a specific "word" appears


2004-11-25 02:43:06 PM
jbuilder12
Hi All,
Given some XX.txt file I want to be able to identify using
java, on which line a particular word appears. Is there a java code snippet that you can suggest?
Thanks in advance for your response.
Bob H
 
 

Re:Line number of a specific "word" appears

Bob H wrote:
Quote
Hi All,

Given some XX.txt file I want to be able to identify using
java, on which line a particular word appears. Is there a java code snippet that you can suggest?

Thanks in advance for your response.

Bob H
Bob,
Do not ask us to write your homework assignments for you. If you have
made at least some miniscule attempt at trying to write this code
yourself, and then post it, we might be more inclined to help.
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

Re:Line number of a specific "word" appears

Lori,
Thank you for reminding me of what is to be here.
This was not my homework. And eventually I found in my files
something that did the task for text line numbering.
For the record here and not very pretty:
part of a larger program source noted:
// source: www.cs.arizona.edu/azapcs/java.htm
/**
* Grant D Hawkes
* AVLTree.java
* 7-7-02
/*
....................
public static void main(String[] args) throws
java.io.IOException
{
AVLTree avl = new AVLTree();
String[] retainWrdLineNum = new String[100];
int ic = 0;
String delims = " ";
StringTokenizer st = null;
BufferedReader br = new BufferedReader(new
FileReader("testStrings.txt"));
String sx;
int i = 0;
int j = 0;
// new
Vector temprecords = new Vector(0);
while((sx=br.readLine()) != null)
{
j = 0;
st = new StringTokenizer(sx,delims);
String[] line_records = new String[9];// now 9 to
accomodate lines of equal membership?
while(st.hasMoreTokens())
{
line_records[j] = st.nextToken();
j++;
}
// New
temprecords.add (line_records);
i++;
}
for(i=0; i < temprecords.size(); i++)
{
String[] curr = (String[])temprecords.elementAt (i);
// Go through fields
for(j=0; j < curr.length; j++)
{
// Output field
System.out.print (curr[j] + " ");
retainWrdLineNum [ic] = curr[j] + " "+ (i+1);
//System.out.println("Insert and Delete TEST1");
avl.insert(curr[j] + " ");
++ic;
//avl.printTeams(); // test1
}
// move down a line
System.out.println ();
avl.printTeams(); // test1
}
String temp3;
System.out.println(ic);
System.out.println("Sorting");
for (int ia = 0; ia < ic-1; ++ia) {
for (int ib = 0; ib if
(retainWrdLineNum[ib].compareTo(retainWrdLineNum[ib +
1])>0) {
temp3 = retainWrdLineNum[ib];
retainWrdLineNum[ib] = retainWrdLineNum[ib + 1];
retainWrdLineNum[ib + 1] = temp3;
}
}
}
System.out.println("Sorted");
System.out.println(" ");
System.out.println("WrdCnt Wrd LocInLine# ");
for(int id= 0;id < ic;++id){
System.out.println(id + ". " + retainWrdLineNum[id]);
}
} // end of static void main
} // end of AVLTree
Bob H
"Lori M Olson [TeamB]" < XXXX@XXXXX.COM >wrote:
Quote
Bob H wrote:

>Hi All,
>
>Given some XX.txt file I want to be able to identify using
>java, on which line a particular word appears. Is there a java code snippet that you can suggest?
>
>Thanks in advance for your response.
>
>Bob H


Bob,

Do not ask us to write your homework assignments for you. If you have
made at least some miniscule attempt at trying to write this code
yourself, and then post it, we might be more inclined to help.

--

Regards,

Lori Olson [TeamB]

------------

Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.

Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html

 

{smallsort}