Reading delimited CSV files

Windows specific forum
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Reading delimited CSV files

Post by PB&J Lover »

Hello PB users,

Is there a simple (native) way to read in a comma delimited csv file with PB? In another language they had inputto which allowed you to give it a character for the delimiter.

Or do I have to do it the hard way and parse each line?

Thanks again.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Command is StringField(String$, Index, Delimiter$)
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Post by PB&J Lover »

Yes, I did know to use that. I was just asking if there was a way to read in a delimted file directly. But this will work. Thanks.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

PB&J Lover wrote:I was just asking if there was a way to read in a delimted file directly.
isnt that directly?
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Post by PB&J Lover »

Well, no. First I have to read in the string, then I set up a parcing routine with with FindString() but I'll also have to move the position variable for each find.

A direct method would be:

Code: Select all

A$(x) = inputto$(#File,Delimiter$)
Where "inputto$" reads the delimited file directly into a variable as a loop advances the index (this sort of thing is very PB-like).

But I can set up the parcing routine for each line read in.

Thanks.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

That would be good.

If PureBasic implemented a "split" function, creating arrays from char delimited strings, it would be good too, and much faster than doing this through a countfield/stringfield loop process.

And (on a roll) allowing the seperator to be longer than one char would also be good!
@}--`--,-- A rose by any other name ..
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

ah okay misunderstood it.
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

I've dealt with loading CSV files a few times before, i would post my code for you, but i'm at work and it's at home >.<

Anyhow, what would be really awesome is a version of the php explode command for PB. it is so much more usefull than *just* csv files.
--Aszid--

Making crazy people sane, starting tomorrow.
Post Reply