Associative array mapping strings to strings

Jarrett Billingsley kb3ctd2 at yahoo.com
Sat Apr 15 00:00:50 PDT 2006


"Andrew Madigan" <amadigan at gmail.com> wrote in message 
news:e1pnqr$rh4$1 at digitaldaemon.com...
>>   char[][] headerNames = strings.keys;
>>   for (int i = 0; i < headerNames.length; i++)    {
>>           writefln("%s: %s", headerNames[i], strings[headerNames[i]]);
>>   }
> Yeah, I just realized that as well. Thank you for your quick response. The
> code works fine now. Thanks again.

Of course, this isn't the most efficient way to iterate through an AA, as it 
has to dynamically create the keys array, and then iterate through it.  It's 
better to do

foreach(char[] key, char[] value; strings)
    writefln(key, ": ", value);

This traverses the AA directly, without allocating memory for the keys 
array. 





More information about the Digitalmars-d-learn mailing list