Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scan.useDelimiter(",")

 
Brett Freedman
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to read in a comma delimited file with Scanner. This works for me with the default space delimiter but I want to use comma since I have some team names with two words.

Here is my code:



Here is part of my input file:


 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

you must use , (comma) and \n (new line) as your delimiters, since lines are separated by new lines.
Try this:

 
Brett Freedman
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ireneusz Kordal wrote:Hi,

you must use , (comma) and \n (new line) as your delimiters, since lines are separated by new lines.
Try this:



Thanks, Ireneusz! This didn't entirely clear up my problem but got me going in the right direction. There were apparently some extra non-visible characters tacked onto the last field of each line mucking up the works. I ended up scanning in one line at a time, splitting that string into tokens and trimming the last field.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic