Crazy stuff

Tower Ty tytower at hotmail.com.au
Sun Apr 27 14:47:48 PDT 2008


Simen Kjaeraas Wrote:

> Tower Ty <tytower at hotmail.com.au> wrote:
> 
> > Thanks -now to stick the hair back. Would never have thought of  
> > approaching it with append . Logically I just want to put it in a firm  
> > place with a defined index address.
> >
> > Does not seem to be covered in the Tango book either.
> 
> This works just as well:
> 
>    string[] a = ["Hello", "World"];
>    string[][] b;
> 
>    b.length = 2;
> 
>    b[0] = a.dup;
> 
>    a[0] = "HAI";
>    a[1] = "WURLD!1";
> 
>    b[1] = a.dup;
> 
>    writefln(b); // prints [[Hello,World],[HAI,WORLD!!!1]]
> 
> 
> Now, without the b.length = 2;, you'll get an array bounds error, of  
> course.
> 
> > So can you explain how you are using " string".
> > What are you importing to be able to use string?
> 
> I'm just importing std.stdio. I think string is a compiler-defined alias,  
> but I
> can't say whence I got the idea.
> 
> -- Simen
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?

Here is an output example printed after each addition

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00, 4, 12/12/06, 0123459, Hermans Hamstack the local Pig Farm and producer, 310, 315.00, 0.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00, 4, 12/12/06, 0123459, Hermans Hamstack the local Pig Farm and producer, 310, 315.00, 0.00, 5, 12/12/06, 0123460, Hermans Halstack, 300, 96.00, 0.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00, 4, 12/12/06, 0123459, Hermans Hamstack the local Pig Farm and producer, 310, 315.00, 0.00, 5, 12/12/06, 0123460, Hermans Halstack, 300, 96.00, 0.00, 6, 12/12/06, 0123461, Hermans Heystack, 290, 1841.00, 0.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00, 4, 12/12/06, 0123459, Hermans Hamstack the local Pig Farm and producer, 310, 315.00, 0.00, 5, 12/12/06, 0123460, Hermans Halstack, 300, 96.00, 0.00, 6, 12/12/06, 0123461, Hermans Heystack, 290, 1841.00, 0.00, 7, 14/12/08, 234999, Hermans Huystack, 311, 234.00, 0.00 ]

[ 8, 15/12/08, 235000,, ermans Heystuck,, 20,, 0.00,0., 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00, 4, 12/12/06, 0123459, Hermans Hamstack the local Pig Farm and producer, 310, 315.00, 0.00, 5, 12/12/06, 0123460, Hermans Halstack, 300, 96.00, 0.00, 6, 12/12/06, 0123461, Hermans Heystack, 290, 1841.00, 0.00, 7, 14/12/08, 234999, Hermans Huystack, 311, 234.00, 0.00, 8, 15/12/08, 235000, Hermans Heystuck, 220, 60.00, 0.00 ]


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?


More information about the Digitalmars-d-learn mailing list