1. reading CSV file doesn't work as expected

What is wrong with this code?

include std/pretty.e 
include std/sequence.e 
include std/io.e 
atom fn = open( "eingabe.csv", "r" ) 
object data = read_lines( fn ) 
close(fn) 
sequence mist = split(",",data[1]) 
puts(1,data[1]) 
puts(1,"\n") 
pretty_print(1,mist[2]) 
-- this line gives an error because data[1] wasn't splitted as expected 
-- mist[1] still contains the whole inputstring of line no. 1 
puts(1,"\n") 

I've tried different solutions with the split function in regex.e and an appropriate regular expression but that doesn't work either. In this case, the sequence mist contains another sequence that contains all the single bytes of data[1]. I experimented already a few hours with no useful results. Maybe I have overseen something.

Thanks in advance for helping me!

Norbert

new topic     » topic index » view message » categorize

2. Re: reading CSV file doesn't work as expected

Norbert said...

What is wrong with this code?

include std/pretty.e 
include std/sequence.e 
include std/io.e 
atom fn = open( "eingabe.csv", "r" ) 
object data = read_lines( fn ) 
close(fn) 
sequence mist = split(",",data[1]) 
puts(1,data[1]) 
puts(1,"\n") 
pretty_print(1,mist[2]) 
-- this line gives an error because data[1] wasn't splitted as expected 
-- mist[1] still contains the whole inputstring of line no. 1 
puts(1,"\n") 

I've tried different solutions with the split function in regex.e and an appropriate regular expression but that doesn't work either. In this case, the sequence mist contains another sequence that contains all the single bytes of data[1]. I experimented already a few hours with no useful results. Maybe I have overseen something.

Thanks in advance for helping me!

It looks like you're calling the split() function incorrectly. Try:

sequence mist = split( data[1], ',' ) 

Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: reading CSV file doesn't work as expected

Matt, thanks a lot for your fast help!

Now it works as expected.

Regards, Norbert

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu