Sort IDictionary<String,Int32> by Value ascending?

I am trying to figure out what order a list of strings appear in a text document. I am reading the text document and storing it in a String variable, “strText”.

For example strText = “Kaila, Kaitlyn, Storm, Daniel, Soul”

I also have a List variable, “listNames”
For example listNames= {“Storm”, “Kaitlyn”, “Daniel”, “Kaila”, “Soul”}

I am using a For Each loop on listNames to assign an Int32 variable called ‘charIndex’ to get the starting index of each name in the list, and then adding the item from listNames and the charIndex to a dictionary variable <String,Int32>, called “nameIndexes”.

I now need to sort the dictionary by the values (int32) asending, but I’m not sure how to do that. I am trying to do nameIndexes.Keys.OrderBy() but I don’t know what the parameters of OrderBy should be, I have looked at this microsoft doc but I’m having trouble figuring out exactly what i need to put for the values of the parameters:

Any help is greatly appreciated :slight_smile:
Thank you!

Here is a workflow example of what I have so far: test.xaml (7.8 KB)

1 Like

Hi @kappk,

Please examine the updated test.xaml and project.json. You did not provide the manifest file which is project.json which is giving errors in UiPath Studio because a dependency is required. (2.5 KB)

1 Like


Can you try the following expression?

nameIndexes = nameIndexes.OrderByDescending(Function(x) x.Value).ToDictionary(function(y) y.Key,function(y) y.Value)



Thank you so much! This worked.

PS - the missing package was Microsoft.Activities for the Dictionary activities.

1 Like

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