Associative array mapping strings to strings

Andrew Madigan amadigan at gmail.com
Sat Apr 15 00:18:30 PDT 2006


Jarrett Billingsley wrote:

> "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.

Thank you, I was wondering what the syntax was for that. My main language is
Java, I didn't realize it was that easy.

A general thought on D: Given the power and features of the language, and
assuming projects such as wxd and Ares are successful, it could become what
Java was supposed to be, it's already a lot better. I'm really impressed.



More information about the Digitalmars-d-learn mailing list