How to check string present in dictionay or not

HI All,
Example Dictionary =
{Sweden;China, Notfound}
{Finland, Notfound}
{Denmark, Notfound}

Variable = Sweden

output Dictionary =
{Sweden;China, found}
{Finland, Notfound}
{Denmark, Notfound}

Need to check whether dictionary key contains input string or not

we do have the ContainsKey(yourKey) / ContainsValue(YourValue)
we can use LINQ
we can check the keys / the values lists

to get a new dictionary similiar to your output we could use LINQ

Assign Activity:
dictUpdated =

(From x in YourOriginDict
Let chk = x.Key.toUpper.Contains(YourCheckStringVar.toUpper)
Let v = If(chk, "found", "Notfound")
Select t = Tuple.Create(x.Key, v)).ToDictionary(Function (t) t.Item1,Function (t) t.Item2)

Or

(From x in YourOriginDict.Keys
Let chk = x.toUpper.Contains(YourCheckStringVar.toUpper)
Let v = If(chk, "found", "Notfound")
Select t = Tuple.Create(x, v)).ToDictionary(Function (t) t.Item1,Function (t) t.Item2)

Or

YourOriginDict.ToDictionary(Function (x) x.Key, Function (x) If(x.Key.Contains(YourCheckVar), "found", "Notfound"))

However we would recommend to check if a simple True/False return check maybe better fits instead to have dictionary defining the check value

2 Likes

thanks you so much for the quick help

just a small things as per your recommed how can i check for simple true or false

myCheckBool = dictVar.Keys.Any(Function (x) x.toUpper.Contains(chkVar.toUpper))

[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

1 Like

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