Array COnversion

with I/P as follows:
“He rang the Bell I rang the Bell everyone rang the Bell”

if i want to count the of repeated words ex: rang -3, is it Mandatory to convert the string to Array and then Dictionary…

cannot we use group by function in Dictionary - i am not expert in datasets so pls guide me

the following is the code i have:
arrLin.Groupby(function (x) x.ToUpper()).ToDictionary(Function (x)x.Key, Function(x) x.Count)

@devasaiprasad_K

You can use split for it

Stringvar.ToLower.Split({"rang"},Stringsplitoptions.None).Length-1

Cheers

Hi @devasaiprasad_K

Try this way

Assign-> sentence = "He rang the Bell I rang the Bell everyone rang the Bell"

Assign-> wordCounts = sentence.Split(" "c).GroupBy(Function(word) word.ToUpper()).ToDictionary(Function(group) group.Key, Function(group) group.Count())

Msg Box -> String.Join(vbCrLf,wordCounts)

sentence is of DataType System.String
wordCounts is of DataType System.Collections.Generic.Dicitonary(System.String, System.Int32)


Regards

Hi @devasaiprasad_K

How about the following?

Input.Split({" "c}, StringSplitOptions.RemoveEmptyEntries).
    GroupBy(Function(x) x.ToUpper()).
    Select(Function(Group) $"{group.Key} - {group.Count()}").
    ToArray()

Output:

image

Cheers!!

Hi,

Your expression seems to work well as the following.

Can you try the following sample?

Sequence6.xaml (8.8 KB)

Regards,

can we sort the result in Ascending Order… i am trying to sort using OrderBy function… missing some logic

@devasaiprasad_K

Try this

Input.Split({" "c}, StringSplitOptions.RemoveEmptyEntries).
    GroupBy(Function(x) x.ToUpper()).
    Select(Function(Group) $"{group.Key} - {group.Count()}").
    OrderBy(Function(x) x).
    ToArray()

image

Regards,

trying this code at the activity level… can you help if we can perform the same code using INVOKE CODE Activity

Hi @devasaiprasad_K

Assign-> sentence = "He rang the Bell I rang the Bell everyone rang the Bell"

Use below code in Invoke Code:

Dim wordCounts = sentence.Split(" "c) _
                          .GroupBy(Function(word) word.ToUpper()) _
                          .OrderBy(Function(Group) Group.Count()) _
                          .ToDictionary(Function(Group) Group.Key, Function(Group) Group.Count())

For Each pair In wordCounts
    Console.WriteLine($"{pair.Key} - {pair.Value}")
Next

Invoke Arguments:

image

Regards

where is the Error:

can you share me the xaml once if possible

Hi @devasaiprasad_K

Here you go
Sequence55.xaml (9.5 KB)

Regards

i dont see the data is getting sorted in Asc order

Hi @devasaiprasad_K

Is the below not the expected Output. Please Specify
image

If possible share your workflow. @devasaiprasad_K
Regards

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