• Post Reply Bookmark Topic Watch Topic
  • New Topic

removing multiple ocurences in a string  RSS feed

 
johan van der zen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!