How remove the keys wich empty or null value in de dictionary?

Hi guy,

How can I remove all keys in the variable dictionary of (string, string) which empty or null value?

Hi @VinhQuang

If you want to remove the keypair which key has empty or null value then use the LINQ Expression.

You can use the below expression in assign activity,

- Assign -> dictionaryVar = dictionaryVar.Where(Function(kvp) Not ((String.IsNullOrEmpty(kvp.Value)) andalso String.IsNullOrWhiteSpace(kvp.Value))).ToDictionary(Function(kvp) kvp.Key, Function(kvp) kvp.Value)

Check the below workflow for better understanding, It has removed Key1 key which is empty,

Hope it helps!!

@VinhQuang

filteredDict = dict.Where(Function(pair) Not String.IsNullOrEmpty(pair.Value)).ToDictionary(Function(pair) pair.Key, Function(pair) pair.Value)

1 Like

Thank you very much! It works

It’s my pleasure… @VinhQuang

Happy Automation!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.