Possible to tell what lines a word appears on?

Hello, want to know how i can tell what lines a specific word appears on with all the words in a matrix.

EX

"I went and

ate

pie because

i am a hungry

person and love pie"

ok, now i have every single word in a seperate cell in a String matrix. Heres what i want to do.

I - 1,4

went - 1

and - 1,5

ate - 2

etc.

How to do it?

thanks!

[421 byte] By [concorde18a] at [2007-11-26 12:21:58]
# 1
Read it line by line and Split every line between spaces.Use String.split("\\s"); method to Split the lines into words.Then smile.=)
Redxxiva at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 2
> Read it line by line and Split every line between> spaces.Wouldnt he have to split by new lines?
CaptainMorgan08a at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 3
> > Read it line by line and Split every line between> > spaces.> > Wouldnt he have to split by new lines?Am i following him correctly?=)
Redxxiva at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 4
> Am i following him correctly?Would you be able to tell what line a word was on if you split them by spaces?
CaptainMorgan08a at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 5
> Would you be able to tell what line a word was on if> you split them by spaces?yup. Reading one line at a time.=)
Redxxiva at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 6
> yup. Reading one line at a time.I was just assuming that the whole thing was one String.
CaptainMorgan08a at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 7
> I was just assuming that the whole thing was one> String.oh. could be.haven't thought of that.=)
Redxxiva at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 8
Neither of you got it, re-read my post. I said i have every word in a seperate cell in a matrix. I am not trying to split lines up or anything of that sort. All im trying to do is tell what line/s each word it is on. Refer back to the example... thanks
concorde18a at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 9

> Neither of you got it, re-read my post. I said i have

> every word in a seperate cell in a matrix. I am not

> trying to split lines up or anything of that sort.

> All im trying to do is tell what line/s each word it

> is on. Refer back to the example... thanks

Then you should read the line.

LineReader

or ?

=)

Message was edited by:

Redxxiv

Redxxiva at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 10

i dont need to read the line. Heres what i did, i wrote the words to a file, i used in.readLine() to read the lines. Once i read the lines i used String Tokenizer to get get the plain words. I put those plain words into a matrix and each cell moving down is the next line and each cell moving right is each word. Example:

I went

to the store

cell[0][0]="I"

cell[0][1]="went"

cell[1][0]="to"

cell[1] [1]="the"

cell[1][2]="store"

now ill say it again... All i want to do is tell me what line# each word has come up in. Refer back to the first example in the first post.

concorde18a at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 11

Oh. so all you have to do is to set a line counter.

counting from the start when you read a line, you should just check whenever you read another line.

something like

int lineCounter = 0;

String temp = "";

while ((temp = bufferReader.readLine()) != null) {

lineCounter++; //this should be the one to determine your line number

//Split the words on this line. use your lineCounter

//Do your stuff

}

smile

=)

Redxxiva at 2007-7-7 15:14:30 > top of Java-index,Archived Forums,Socket Programming...
# 12

dude i dont need to know how to count lines. I need to know WHAT LINES EACH WORD HAS BEEN WRITTEN ON. I can just look at the matrix row to see what line its on, i just need to know how to get what lines EACH word is on. I really dont think i can phrase this any better. Simple to comprehend but i dont know why your having so much trouble doing so. Refer back to the first example to see what i mean by checking the words and telling you what lines its on.

concorde18a at 2007-7-7 15:14:31 > top of Java-index,Archived Forums,Socket Programming...
# 13
Ok, sorry about that. so, you already have all this data in your Array.You could create a recursive method to do what you wanted?So, what's wrong?=)....
Redxxiva at 2007-7-7 15:14:31 > top of Java-index,Archived Forums,Socket Programming...
# 14
No need for a recursive method. Use a for-loop to work down the lines ofthe matrix, and a nested for-loop to work along the relevant line. Test thewords and do something appropriate when you have a match.
pbrockway2a at 2007-7-7 15:14:31 > top of Java-index,Archived Forums,Socket Programming...