Hash Compare
Derek Parnell
derek at psych.ward
Wed Apr 18 10:48:25 PDT 2007
On Wed, 18 Apr 2007 12:13:39 -0400, Johnny wrote:
> Hello,
>
> I've got a problem. I need to check if a hash key exists in a for loop like:
>
> int [char[]] a;
> int [char[]] b;
>
> a = { a => 1; b => 5; c=> 8 }
> b = { a => 5; b => 4; d => 3; f => 4 }
>
> foreach (m; a.keys) {
> if ( b[m] ) {
> writefln("%s %s %s", m, a[m], b[m])
> }
> else {
> writefln("%s %s", m, a[m])
> }
> }
>
> ... not "real" D but I hope you understand the code and what it should do.
> Thanks.
Try replacing "if (b[m])" with "if (m in b)".
The correct way to find out if a specific key exists in an AA is to use the
"in" syntax.
--
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell
More information about the Digitalmars-d-learn
mailing list