How to check if dictionary contain String


#1

I have a dictionary whit key (email address) and value (number email send)

I need to check if email already exists in the dictionary

can Somebody help me?


#2

Hello!

Try to use: dictionary.Contains(String).

It will return a True/False value.

Regards,


#3

"impossible cinvert the value “UiPathCore.GenericValue” in “System.Collection.GenericsKeyValuePair(of String, integer)”

Why?


#4

yourDictionary.Keys.Contains(yourString)


#5

@dnllorenzetti there is also a Microsoft.Activities.Extension package available for UiPath that has some useful activities for the Dictionary data type. If you had that installed you could use the Key exists in dictionary activity.


#6

Or just use “Values exists in dictionary” and “Keys exists in dictionary” Activities :smiley:


#7

While they’re useful (especially AddToDictionary, since it’s void), for Exists it’s IMHO more efficient to use the method call.
Compare the 2:
bool keyExists = KeyExistsInDictionary(dictionary, value) if (keyExists) {...}

or

if (dictionary.Keys.Contains(value) {...}

It saves you space on the designer and an extra variable. While it doesn’t sound like much, in more complicated workflows it adds up. It’s still personal/team preference though.


#8

I need to build something that for each key (email) counts how many times a message has been sent.

What do you recommend?