Find occurences of each character in the string

How to find the occurences of each character in the given string-“aadfggggtryionnb”?

refer to this
testnew.xaml (8.7 KB)

create dictionary and loop over each character in string,
for each character,
assign
dict(letter) = str.Where(Function(c) c = letter).Count

result
image

1 Like

are there any other methods?

Hi @ydash999 ,

Check the below Method :

YourStringVar.GroupBy(Function(x)x.ToString).ToDictionary(Function(x)x(0).ToString,Function(y)y.Count)

you can assign this value to a Dictionary of String,Integer variable.

2 Likes

thankss bro

thanksss bro

Hi @ydash999,

count character
Above link is a more simplified solution. Remember to import System.Text.RegularExpressions first
import regex

how can i find occurence of each character with this?

You assign below to a string variable.
“item” will be your string variable

System.Text.RegularExpressions.Regex.Matches(item.ToString,“a”).Count

i dont have to find the total count, but count of occurences of each character

I just edited the “Total” to “a”. This is where you put the character you want to find

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