Crazy stuff

Steven Schveighoffer schveiguy at yahoo.com
Mon Apr 28 22:00:17 PDT 2008


"Tower Ty" wrote
> Goodo I'll give that a try -thanks again.
>
> As an aside I find that with Simens help in the above I can move forward 
> but another problem raises its head with this array business
>
> I am accumulating lines from a text file in my  char[][][] array. It 
> writes the first seven lines of an eight line file OK but on the last line 
> it writes the last line in the correct place but also corrupts the first 
> lines data?
>
> ...
>
> The data is fine unyil the last line
> I produce the data with
>
> foreach (line; new LineIterator!(char) (new FileConduit ("data.csv"))){
>      TableItem item = new TableItem (table, DWT.RIGHT);
>      fields = TextUtil.delimit(line,",");
>
> Anyone have any idea why the data is corrupted?

Yes, LineIterator re-uses the same data buffer while reading the file for 
efficiency.  If you want to save the data that LineIterator gives you, use

fields = TextUtil.delmit(line.dup,",");

What this does is make a copy of the line, then split that up.  When the 
LineIterator re-uses the buffer, it won't affect your copies.

And Tango does not use 'string' as a keyword, that is Phobos only.

Hope that helps.

-Steve 




More information about the Digitalmars-d-learn mailing list