LINQ Query get 2 keys from List(of Dictionary)


This question if connected to Linq SelectMany ListofDictionary - Help / Studio - UiPath Community Forum

I have a List (of Dictionary) with following values
[“name”] = “Adam”,
[“mail”] = “
[“subject”] = “test 123”
[“id”] = 12345
[“name”] = “Deo”,
[“mail”] = “
[“subject”] = “test email”
[“id”] = 678910

I need to do the following:

  1. Get the amount/number in subject (converted in specific format (DE))
  2. Select the id of the subject in List (of Dictionary) if specific content of transactionitem contains the amount in mail subject

TransactionItem.SpecificContent(“amount”) = 123
Desired output:
[“subject”] = “test 123”
[“id”] = 12345

Is it possible to get the id and subject when we select from the list?

Hi @wonderingnoname ,

Not sure, if there is a confusion between the use of SpecificContent method of the QueueItem type.

But we could understand that the Query is to Check whether a Number/Amount is present in the subject value in the list of dictionaries, and if found then also get it’s Id value. Basically, we would get the Dictionary from the list which matches this condition.

In that case, you can check the below Approach :

DictVar = listDict.Where(Function(d) Regex.IsMatch(d("subject").ToString,"\d[\d.,]*")).FirstOrDefault

Then, We can use an If Condition to Check if DictVar contains a value or not like below, then we convert the numeric value from Subject to the required conversion :

Amount = string.Format(new CultureInfo("de-DE"), "{0:C}", Regex.Match(dictVar("subject").ToString,"\d[\d.,]*").Value)

Id = dictVar("id").ToString

dictVar is a variable of Type Dictionary(Of String,String).

Let us know if you are facing any difficulties and also provide for which cases/inputs you get the errors, so that we can correct the method towards that approach.

1 Like


Hope the following sample helps you.

filteredList = listDict.Where(Function(d) System.Text.RegularExpressions.Regex.IsMatch(d("subject"),"(^|\b)"+strAmount+"(\b|$)")).ToList (2.7 KB)


1 Like

Just For Each through the list and get the values you need.

This worked! Thank you!

1 Like

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