interesting problem

Hi!

I've got code which changed text from BufferedReader and save in another txt file, thats the sample of the text from txt file

some text one, two, 3,4...

another line of text

and another

some text one, two, 3,4...

another line of text

and another

.....some text one, two, 3,4...

.....another line of text

.....and another

.............some text one, two, 3,4...

.............another line of text

.............and another

some text one, two, 3,4...

another line of text

and another

when i seesome i add something before this line and everything works fine but i have to add something else whensome is in other clolumn, so i need to get position from the firssome and i will be able to compare wih anothersome and do something different with this paragraph.

I need somethin like getCaretPosition but for BufferedReader

that's my code i hope my question will be more clear now.

Sorry for my english.

Any halp will be appreciate.

import java.io.FileReader;

import java.io.PrintWriter;

import java.util.StringTokenizer;

import java.io.*;

import javax.xml.transform.stream.StreamResult;

publicclass FileSearcher{

publicstaticvoid main (String[] args)throws IOException{

String line;

String files="Doc.txt";

StringTokenizer tokenizer;

BufferedReader inFile =new BufferedReader (new FileReader(files));

PrintWriter out =new PrintWriter(new FileWriter("NewDoc.txt"));

while (inFile.ready()){

line = inFile.readLine();

tokenizer =new StringTokenizer(line);

while(tokenizer.hasMoreTokens()){// loops through each token in line

String word = tokenizer.nextToken();

if (word.equals("some"))// we are searching for the String word

{

out.println(" add text before SOME");

out.println(line);

}

/*i think, somethin should be here, like:

*

* if("some is in other column){

* out.println("add diffren text before SOME");

* }

* */

}

out.println(line);

}

inFile.close();

out.close();

}

}

[3385 byte] By [maciej80a] at [2007-10-2 17:11:43]
# 1

Dont use StringTokenizer.

Try java.lang.String.indexOf("some") instead.

while (inFile.ready()) {

line = inFile.readLine();

int someIndex = line.indexOf("some"); // returns the position of "some" in the line.

if (someIndex == 0) {

} else if (someIndex == x) {

}

....

ordinary_guya at 2007-7-13 18:26:53 > top of Java-index,Other Topics,Algorithms...
# 2

Thanks it works fine, but my problem now is litle different

some text one, two, 3,4...

another line of text

and another

dif. text one, two, 3,4...

another line of text

and another

another text one, two, 3,4...

another line of text

and another

somthing new text one, two, 3,4...

another line of text

and another

new word text one, two, 3,4...

another line of text

and another

so now i don't have the magic word some but each line starts with different word, so how can i recognise the new column?

I think, i have to count white space and compare, but i don't know how to do this?

Please, help.

maciej80a at 2007-7-13 18:26:53 > top of Java-index,Other Topics,Algorithms...