Q:

what is the best way to find substring in a string with its frequency using c#?

I am trying to find a word in a string which means
if abcdef ghijk is a string then substring ghijk should give us 1 as frequency. 
but if substring is cde then 0 should be returned.
i wish this was possible with Regex but I don't know if it is. or may be there is a method in string class.

A:

If you want words frequency, you can create word freq. dictionary like this:
s.Split().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count())

And then check if word in this dictionary.
var s = "abcdef ghijk abcdef";
var d = s.Split().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count())
// Dictionary<string, int>(2) { { "abcdef", 2 }, { "ghijk", 1 } }

A:

It sounds like you want to find only whole words within the string. This can be accomplished with a regular expression using \b, which means 'word boundary'. For example:
var input = "abcdef ghijk";

var freq1 = Regex.Matches(input, @"\bghijk\b").Count;
Console.WriteLine(freq1); // 1

var freq2 = Regex.Matches(input, @"\bcde\b").Count;
Console.WriteLine(freq2); // 0

This will also take into account punctuation like commas and periods.

