how to filter associative arrays with foreach ?
someone
someone at somewhere.com
Thu Jun 24 02:38:04 UTC 2021
On Monday, 21 June 2021 at 08:31:16 UTC, Ali Çehreli wrote:
> Two options for byKey and byKeyValue:
>
>
> import std;
>
> void main() {
> auto aa = [ "WS2" : 42, "WS3" : 43 ];
> string strComputerIDunwanted = "WS2";
> foreach (key; aa.byKey.filter!(k => k !=
> strComputerIDunwanted)) {
> writeln(key, ' ', aa[key]);
> }
>
> // 't' is the tuple of key and value
> foreach (t; aa.byKeyValue.filter!(t => t.key !=
> strComputerIDunwanted)) {
> writeln(t.key, ' ', t.value);
> }
> }
Like 'em both, very flexible indeed, I think there are a couple
of places I could implement this. Thanks for your good advice as
usual Ali :) !
More information about the Digitalmars-d-learn
mailing list