digitalmars.D.learn - generate unique variable names?
- K.K. (12/12) Oct 07 2014 Is there a way to generate variable names using strings? What I'm
- Brian Schott (6/20) Oct 07 2014 I'm 99% sure you actually want an array or associative array.
- K.K. (5/10) Oct 07 2014 oooh okay I see what you mean. Yeah that will be waaaay better.
- Nicolas F. (3/16) Oct 08 2014 Since you're actually already using indexes in the name, you
Is there a way to generate variable names using strings? What I'm trying to do in this particular case is use a for loop, to generate variables (then probably put them in an array in the end) that represent images. So the name is pretty much "image" + the image padding + iterator number. So image001, image002, etc. So visually (though not real syntax): auto "imageName" ~ "imagePadding" ~ i = new Imagefromfile(userDefinedLocation); The problem is I can't figure out how to actually create the unique variable. I was thinking of trying to use 'new' some how, but still not sure. Thanks in advance for any help!
Oct 07 2014
On Wednesday, 8 October 2014 at 01:16:50 UTC, K.K. wrote:Is there a way to generate variable names using strings? What I'm trying to do in this particular case is use a for loop, to generate variables (then probably put them in an array in the end) that represent images. So the name is pretty much "image" + the image padding + iterator number. So image001, image002, etc. So visually (though not real syntax): auto "imageName" ~ "imagePadding" ~ i = new Imagefromfile(userDefinedLocation); The problem is I can't figure out how to actually create the unique variable. I was thinking of trying to use 'new' some how, but still not sure. Thanks in advance for any help!I'm 99% sure you actually want an array or associative array. Something like this maybe? ImageType[string] images; images[format("image%03d", i)] = new ImagefromFile(userDefinedLocation);
Oct 07 2014
On Wednesday, 8 October 2014 at 02:06:28 UTC, Brian Schott wrote:I'm 99% sure you actually want an array or associative array. Something like this maybe? ImageType[string] images; images[format("image%03d", i)] = new ImagefromFile(userDefinedLocation);oooh okay I see what you mean. Yeah that will be waaaay better. It'll help me get rid of all my extra temp variables and string/int conversions, too. Thanks! :)
Oct 07 2014
On Wednesday, 8 October 2014 at 02:53:08 UTC, K.K. wrote:On Wednesday, 8 October 2014 at 02:06:28 UTC, Brian Schott wrote:Since you're actually already using indexes in the name, you might as well use a regular array of the appropriate sizeI'm 99% sure you actually want an array or associative array. Something like this maybe? ImageType[string] images; images[format("image%03d", i)] = new ImagefromFile(userDefinedLocation);oooh okay I see what you mean. Yeah that will be waaaay better. It'll help me get rid of all my extra temp variables and string/int conversions, too. Thanks! :)
Oct 08 2014