Count Occurence of each element in a string[] and extract it (assign) to a variable

Hi All,

Let’s assume the input is “yes yes yes no no”, the printed outcome is
3 Yes
2 No

i’m using for each loop, and we are able to print the countUnique using write line (within the for each loop)

Step 1:
i’m trying to extract the values of (3 Yes 2 No) and assign it into a variable (let’s call it List), as a list[string],

Step 2:
so that i can recall it individually as part of string.format (" no. of {0} and no. of {1}", List) later.

no. of 3 yes and no. of 2 no

Assigning to a variable / or add-to-a-collection then assign to a variable outside for loop doesn’t seem works. count occurrencemaster1.xaml (9.3 KB)

Please help.

You can use System.Text.RegularExpressions.Regex.Matches(Join(varStringArray," "), "yes").Count

1 Like

@hcw
find a demo xaml here:
Count_ValueOccurence_ResultDict.xaml (6.1 KB)

it was mentioned in the title that the source is a string Array. If the values are instead in a string like “yes yes yes no no” as mentioned, a StringVar.Split(" “c) can be used to create a String array as {“yes”,“yes”,“yes”,“no”,"no”}