Re: Reading comma delimited .csv data files

new topic     » goto parent     » topic index » view thread      » older message » newer message

JAYBEEDEE wrote:

> For example, the csv file might be of the form:
> 
> Month,,
> 6,,
> 8,,
> 1988,,
> 
> 
> 2,6,8
> 5,12,25.7
> . 
> etc

So should that data be like

{
   { "Month", "" }
  ,{ 6, 0 }
  ,{ 8, 0 }
  ,{ 1988, 0 }
}

Why is 1988 in the month column?!

Anyway, this is very easy to do. Basically:

fn = open("myExcelOutputFile.csv","r")
line = gets( fn )
while sequence(line) do
 cols = parse(line,",") --<-- search Euphoria archive for this functionality
 grid = append(grid,cols)
 line = gets( fn )
end while
close(fn)


Now you can get values with grid[row][col].

parse() takes a line of text and separates it using the separator you provide.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu