DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   tab separated file (http://www.daniweb.com/forums/thread158118.html)

mrjoli021 Nov 18th, 2008 3:21 pm
tab separated file
 
I have a file that is tab separated. i read it in as an arraylist<string> how can i print out only the second section of the file?

Ezzaral Nov 18th, 2008 3:33 pm
Re: tab separated file
 
That depends what "second section" means. If you can't be more specific than that, you have little chance of getting a program to do something with it.

mrjoli021 Nov 18th, 2008 3:36 pm
Re: tab separated file
 
the file is tab separated into three sections.

section1 section2 section3

i only want to read section2

Ezzaral Nov 18th, 2008 3:38 pm
Re: tab separated file
 
Then use String.split() to separate it and read the second element of the result.

mrjoli021 Nov 18th, 2008 4:13 pm
Re: tab separated file
 
array is an arraylist<string>

 for (int i = 0; i<array.size(); i++)
        {
            System.out.println(array.get(i).split(" "));
           
        }

i get: [Ljava.lang.String;@ca0b6

i am supposed to get "10.0.0.2"

Ezzaral Nov 18th, 2008 4:25 pm
Re: tab separated file
 
Did you read the api doc on split() at all?

mrjoli021 Nov 18th, 2008 4:46 pm
Re: tab separated file
 
yes and according to the instructions that is how u should use it.

Ezzaral Nov 18th, 2008 4:51 pm
Re: tab separated file
 
Really? Because this particular part would seem to be clearly saying something else
Quote:

Returns:
the array of strings computed by splitting this string around matches of the given regular expression
Notice the array part.

(Also, there does not appear to be anyone named "u" here at the moment. Use proper English.)

mrjoli021 Nov 18th, 2008 4:57 pm
Re: tab separated file
 
i read it again and i still understand the same thing.

i obiously dont understand how to use it.

can you help me out or not.

Ezzaral Nov 18th, 2008 5:29 pm
Re: tab separated file
 
It splits on a particular expression, which in your case should be tab, and returns an array of the pieces. If you want the second section then you just need the second element of that array.


All times are GMT -4. The time now is 6:46 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC