This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

read from csv

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I get a file on a monthly basis with the EXACT fromat. it looks somthing like this:

code agetn number name state account
----+-----+-------+-----------+------+---------------
423 8834 9934 Washington 993 2993
652 9234 2203 Dallas 441 9223
999 8888 0002 North, East 434 3552

the last raw is SOOO problematic because my csvreader believe that the next token is a state number while it is a string [EAST] this is of course because of the comma: North, East.

anyone have a nice solution for this?
thanks
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Update your parser to handle it?

Seriously, I'm a bit confused because you're showing the data as space separated but your indicating a problem with commas. Which way is it? I would say that the data is not in the correct format if you mean to have commas as the delimiter. The traditional manner is that each field is surrounded by the double quote character so that you really separate by them, not the commas. Of course, having an embedded double quote character then needs to be addressed if your data supports it.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the data is taken from a csv file - so this means that it is separated by commas. I meant the space to represent the commas.
 
author and iconoclast
Posts: 24206
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You said,

Originally posted by Peter Primrose:

I get a file on a monthly basis with the EXACT fromat.



(Emphasis yours.) But then later you tell us that this is in fact not the exact format -- in fact, that the real data is comma separated, and your sample is not!

How about this: show us a few good lines and one troublesome line from your real data, and we'll be in a much better position to advise you.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the exact format. North, east always comes this way; and the problem is what stated above.

my code looks like this (the simple version):

 
Ernest Friedman-Hill
author and iconoclast
Posts: 24206
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Peter Primrose:
I meant the space to represent the commas.



And then

this is the exact format.





What I'm saying is that unless you show us exactly what the file looks like, we might be missing an opportunity. If the fields are always the same size, then we could use that. If there are always exactly 7 numbers at the end, we could use that. If that "Washington/Dallas/North, East" field never contains any digits, we could use that. But we can't help you parse a file whose format is unknown to us.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CSV has a number of edge cases that you need to consider. Why reinvent the wheel when there are ready-made libraries that can do CSV-handling for you?
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you all.... the csvreader solves it.
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic