my dog learned polymorphism
The moose likes Beginning Java and the fly likes removing multiple ocurences in a string Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "removing multiple ocurences in a string" Watch "removing multiple ocurences in a string" New topic
Author

removing multiple ocurences in a string

johan van der zen
Greenhorn

Joined: Sep 21, 2006
Posts: 6
hello ranchers

i am coding a method that recieves an arraylist as a parameter, in it there are multiple rows of string in this format: data1;data2;data3;.....datan;
i need to parse each row of the list in order to get every single data item in it so i can then build an excel sheet with this data but that's another story what i cannot seem to do propertly is the correct parsing of the string can anyone help me?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
when you say excel, do you mean excel-like, as in JTable?
if so,
you can use String.split() for each line, to return a String[]
the String[] can be used as an argument for a vector (Collection)
this vector is then added to another vector

once you have all your data read in, the vector of vectors
is the 'row' argument for the TableModel of the JTable
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, welcome to the ranch!

Is there any chance your data can have a semi-colon in it? What would that look like? Some escape mechanisms can make this a little harder.

BTW: If you just change all the semi-colons to tabs and write it back to disk, Excel will open it right up.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: removing multiple ocurences in a string
 
Similar Threads
Dojo Datagrid
multiple access to same data in database by multiple requests?
array to object - why?
How can i reset the form bean data
Looking for an appropriate data structure