Re: Dynamic array of strings and appending a zero length array

2023-07-09 Thread Cecil Ward via Digitalmars-d-learn
On Saturday, 8 July 2023 at 20:01:08 UTC, H. S. Teoh wrote: On Sat, Jul 08, 2023 at 05:15:26PM +, Cecil Ward via Digitalmars-d-learn wrote: I have a dynamic array of dstrings and I’m spending dstrings to it. At one point I need to append a zero-length string just to increase the length of t

Re: Dynamic array of strings and appending a zero length array

2023-07-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 08, 2023 at 05:15:26PM +, Cecil Ward via Digitalmars-d-learn wrote: > I have a dynamic array of dstrings and I’m spending dstrings to it. At > one point I need to append a zero-length string just to increase the > length of the array by one but I can’t have a slot containing garbag

Re: Dynamic array of strings and appending a zero length array

2023-07-08 Thread FeepingCreature via Digitalmars-d-learn
On Saturday, 8 July 2023 at 17:15:26 UTC, Cecil Ward wrote: I have a dynamic array of dstrings and I’m spending dstrings to it. At one point I need to append a zero-length string just to increase the length of the array by one but I can’t have a slot containing garbage. I thought about ++arr.le

Re: Dynamic array of strings and appending a zero length array

2023-07-08 Thread Cecil Ward via Digitalmars-d-learn
On Saturday, 8 July 2023 at 17:15:26 UTC, Cecil Ward wrote: I have a dynamic array of dstrings and I’m spending dstrings to it. At one point I need to append a zero-length string just to increase the length of the array by one but I can’t have a slot containing garbage. I thought about ++arr.le

Dynamic array of strings and appending a zero length array

2023-07-08 Thread Cecil Ward via Digitalmars-d-learn
I have a dynamic array of dstrings and I’m spending dstrings to it. At one point I need to append a zero-length string just to increase the length of the array by one but I can’t have a slot containing garbage. I thought about ++arr.length - would that work, while giving me valid contents to th

Re: Multidimensional dynamic array of strings initialized with split()

2017-09-22 Thread Ludovit Lucenic via Digitalmars-d-learn
On Thursday, 5 September 2013 at 16:22:46 UTC, Ali Çehreli wrote: Compiling with "DMD64 D Compiler v2.064-devel-52cc287" produces the following errors: * You had byLines in your original code as well. Shouldn't it be byLine? * You are missing the closing brace of the foreach loop as well.

Re: Multidimensional dynamic array of strings initialized with split()

2013-09-05 Thread Ali Çehreli
On 09/05/2013 01:14 AM, Ludovit Lucenic wrote: I have created a wiki on this one. http://wiki.dlang.org/Read_table_data_from_file Compiling with "DMD64 D Compiler v2.064-devel-52cc287" produces the following errors: * You had byLines in your original code as well. Shouldn't it be byLine? *

Re: Multidimensional dynamic array of strings initialized with split()

2013-09-05 Thread Ludovit Lucenic
I have created a wiki on this one. http://wiki.dlang.org/Read_table_data_from_file

Re: Multidimensional dynamic array of strings initialized with split()

2013-09-04 Thread Ludovit Lucenic
On Wednesday, 4 September 2013 at 23:06:10 UTC, H. S. Teoh wrote: The problem is that File.byLine() reuses its buffer for efficiency, and split is optimized to return slices into that buffer instead of copying each substring. So after every iteration the buffer (and therefore the slices into

Re: Multidimensional dynamic array of strings initialized with split()

2013-09-04 Thread H. S. Teoh
On Thu, Sep 05, 2013 at 12:57:34AM +0200, Ludovit Lucenic wrote: > Hello friends, > > with the following code > > import std.stdio; > import std.array; > > auto file71 = File(argv[2], "r"); > > string[][] buffer; > foreach (line; file71.byLines) { > buffer ~= split(line, "\t"); > } > > I a

Multidimensional dynamic array of strings initialized with split()

2013-09-04 Thread Ludovit Lucenic
Hello friends, with the following code import std.stdio; import std.array; auto file71 = File(argv[2], "r"); string[][] buffer; foreach (line; file71.byLines) { buffer ~= split(line, "\t"); } I am trying to cut the lines from the file with tab as delimiter to pre-fetch the content of a f

Re: dynamic array of strings

2009-01-01 Thread Gide Nwawudu
On Tue, 30 Dec 2008 10:56:08 -0500, Michael P. wrote: >Jarrett Billingsley Wrote: > >> On Mon, Dec 29, 2008 at 10:36 PM, Michael P. wrote: >> > import std.stdio; >> > import std.cstream; >> > void main() >> > { >> > char[][] names; >> > char[] currentName; >> > while( true ) >> > { >> >d

Re: dynamic array of strings

2008-12-30 Thread Michael P.
>Well, let's go through the code. > > First of all, you should undestand that an array is nothing but a pair of > pointer to first element and its length. > > Since char[] == string in D1, let's use string instead to make code slightly > more readable. > > string[] names; // array of strings t

Re: dynamic array of strings

2008-12-30 Thread Denis Koroskin
On Tue, 30 Dec 2008 20:34:00 +0300, Michael P. wrote: Denis Koroskin Wrote: On Tue, 30 Dec 2008 20:23:07 +0300, Michael P. wrote: > Denis Koroskin Wrote: > >> On Tue, 30 Dec 2008 18:56:08 +0300, Michael P. >> wrote: >> >> > Jarrett Billingsley Wrote: >> > >> >> On Mon, Dec 29, 2008 at

Re: dynamic array of strings

2008-12-30 Thread Michael P.
Denis Koroskin Wrote: > On Tue, 30 Dec 2008 20:23:07 +0300, Michael P. wrote: > > > Denis Koroskin Wrote: > > > >> On Tue, 30 Dec 2008 18:56:08 +0300, Michael P. > >> wrote: > >> > >> > Jarrett Billingsley Wrote: > >> > > >> >> On Mon, Dec 29, 2008 at 10:36 PM, Michael P. > >> >> wrote: > >>

Re: dynamic array of strings

2008-12-30 Thread Denis Koroskin
On Tue, 30 Dec 2008 20:23:07 +0300, Michael P. wrote: Denis Koroskin Wrote: On Tue, 30 Dec 2008 18:56:08 +0300, Michael P. wrote: > Jarrett Billingsley Wrote: > >> On Mon, Dec 29, 2008 at 10:36 PM, Michael P. >> wrote: >> > import std.stdio; >> > import std.cstream; >> > void main() >> >

Re: dynamic array of strings

2008-12-30 Thread Michael P.
Denis Koroskin Wrote: > On Tue, 30 Dec 2008 18:56:08 +0300, Michael P. wrote: > > > Jarrett Billingsley Wrote: > > > >> On Mon, Dec 29, 2008 at 10:36 PM, Michael P. > >> wrote: > >> > import std.stdio; > >> > import std.cstream; > >> > void main() > >> > { > >> > char[][] names; > >> > char

Re: dynamic array of strings

2008-12-30 Thread Denis Koroskin
On Tue, 30 Dec 2008 18:56:08 +0300, Michael P. wrote: Jarrett Billingsley Wrote: On Mon, Dec 29, 2008 at 10:36 PM, Michael P. wrote: > import std.stdio; > import std.cstream; > void main() > { > char[][] names; > char[] currentName; > while( true ) > { >din.readf( "%s", ¤tName ); >

Re: dynamic array of strings

2008-12-30 Thread Michael P.
Jarrett Billingsley Wrote: > On Mon, Dec 29, 2008 at 10:36 PM, Michael P. wrote: > > import std.stdio; > > import std.cstream; > > void main() > > { > > char[][] names; > > char[] currentName; > > while( true ) > > { > >din.readf( "%s", ¤tName ); > >if( currentName == "stop" ) > >

Re: dynamic array of strings

2008-12-29 Thread Tim M
On Tue, 30 Dec 2008 17:00:10 +1300, Jarrett Billingsley wrote: On Mon, Dec 29, 2008 at 10:53 PM, Tim M wrote: Where is din.readf? If it is a c function then it won't be able to set up the dynamic array. In std.cstream, din is an instance of std.stream.Stream bound to standard in.

Re: dynamic array of strings

2008-12-29 Thread Jarrett Billingsley
On Mon, Dec 29, 2008 at 10:53 PM, Tim M wrote: > > Where is din.readf? If it is a c function then it won't be able to set up > the dynamic array. In std.cstream, din is an instance of std.stream.Stream bound to standard in.

Re: dynamic array of strings

2008-12-29 Thread Tim M
On Tue, 30 Dec 2008 16:36:24 +1300, Michael P. wrote: import std.stdio; import std.cstream; void main() { char[][] names; char[] currentName; while( true ) { din.readf( "%s", ¤tName ); if( currentName == "stop" ) { break; } else { //what goes here t

Re: dynamic array of strings

2008-12-29 Thread Jarrett Billingsley
On Mon, Dec 29, 2008 at 10:36 PM, Michael P. wrote: > import std.stdio; > import std.cstream; > void main() > { > char[][] names; > char[] currentName; > while( true ) > { >din.readf( "%s", ¤tName ); >if( currentName == "stop" ) >{ > break; >} >else >{ names ~= cur

dynamic array of strings

2008-12-29 Thread Michael P.
import std.stdio; import std.cstream; void main() { char[][] names; char[] currentName; while( true ) { din.readf( "%s", ¤tName ); if( currentName == "stop" ) { break; } else { //what goes here to dynamically allocate memory for the //names array? n