trouble with associative Arrays

Renato renato at athaydes.com
Sat Jan 20 15:39:27 UTC 2024


On Saturday, 20 January 2024 at 15:16:00 UTC, atzensepp wrote:
> The section looks now simpler although I guess that there are 
> more appropriate mechanisms available (csvreader):
>
>     string [] orgids[string];
>     foreach (line; range)
>     {
>         if (!line.empty)
>         {
>             auto row = line.split(";");
>             string word = row[1];
>             if(word.length>0 && word[0] == '\"')
>                     word= word[1 .. $-1];
>             orgids[word]=row;
>             i++;
>         }
>     }

Maybe a bit more readable:

```d
  import std.string :  strip, split;
  string [] orgids[string];
  foreach (line; range)
  {
      if (line.empty) continue;
      auto row = line.split(";");
      auto word = row[1].strip("\"");
      orgids[word] = row;
      i++;
  }
```


More information about the Digitalmars-d-learn mailing list