What did that program do? Did it get the part of the String that you want?

Quote:

problem is working with more than one line.

Can you identify what line has the data so you can use split to extract the part you want?
Pseudo code:
begin loop
read line
if this line has the data
then extract the data from this line
end loop

January 21st, 2013, 01:03 PM

JosPhantasmE

Re: Print just what I want, help me with my code.

It printed "Pos001"

And with what you are suggesting, I dont think thats gonna work for me.

Because the data will always be different, "pos001" is just an example.

I will want the last word of the line #3 in the string...

January 21st, 2013, 01:07 PM

Norm

Re: Print just what I want, help me with my code.

This line:

Code :

System.out.println(str.split(" ")[2]);

will print the third element in the array that was split from the String contained in str.
The contents of str would be what was read into the variable line in the loop in the registry reading program.
Replace str with line to see what you need in the main program.

Remember when you tried using substring and got errors because the line was empty?
Now you are having the same problem again. The code needs to look at the line to see if it is long enough.
Also it needs to look at the size of the array returned by the split method to see if it has 3 elements before trying to access the third element.

I posted this pseudo code on what the code needs to do:
You need to identify what line has the data so you can use split to extract the part you want:

Pseudo code:
begin loop
read line
if this line has the data <<<<<<<<<<<< NEED THIS TEST
then extract the data from this line
end loop

Is printing the info that I want 5 times. Which is suppose to be only 1.

January 21st, 2013, 04:49 PM

Norm

Re: Print just what I want, help me with my code.

How many lines does the code read in the loop? What are on those lines?
Are there 5 lines with the same data?
How many times does the loop execute?

You need to debug your code to see how it is executing. Add some println statements that shows where the execution flow is going and what is being read. The code has nested loops that could be executing the inner loop more than once. Print out some messages to see what the code is doing.

January 21st, 2013, 05:28 PM

JosPhantasmE

Re: Print just what I want, help me with my code.

I'm so confuse I dont know what could it be...

When I run a System.out.println(check1); afther the while it print the whole string 5 times, and IDK why, can you help me understand?

January 21st, 2013, 05:46 PM

Norm

Re: Print just what I want, help me with my code.

How many times was the inner loop executed?
How many times do you want it to execute?

I don't understand why there is an inner loop that can be executed more than one time.
Every time it is executed it executes the same reg command and gets the same response.
If it is executed 5 times, it will print out the string 5 times.

January 21st, 2013, 06:09 PM

JosPhantasmE

Re: Print just what I want, help me with my code.

I mean it gets executed only one time,. thats my entire code right there.

January 21st, 2013, 06:39 PM

Norm

Re: Print just what I want, help me with my code.

Quote:

it gets executed only one time

Did you add a println to print out a message every time the reg command is executed?
How many times did it print out a message that the reg command was being executed?

January 22nd, 2013, 05:34 PM

JosPhantasmE

Re: Print just what I want, help me with my code.

It print the job 5 times. I think I found the problem but not sure how to solve, everything is inside a while statement, that might be the problem, but how can I assign a "else" to the if statement that is inside that while statement without being inside the same while statement, does that make sense?