using System.Collections.Generic;
static IEnumerable<KeyValuePair<string, int>> Fiddle(string sourceString, int patternLength)
throw new ArgumentException("input patter lenght must be positive", "patternLength");
if (sourceString.Length >= Int32.MaxValue)
throw new ArgumentException("input string length larger than Substring can handle", "sourceString");
if (patternLength > sourceString.Length)
throw new ArgumentException("patternLength value larger than input string length", "patternLength");
var myDict = new Dictionary<string, int>();
for (var index = sourceString.Length - patternLength; index >= 0; --index)
var pattern = sourceString.Substring(index, patternLength);
if (myDict.TryGetValue(pattern, out count))
myDict[pattern] = count + 1;
foreach (var record in myDict)
public static void Main()
var result = Fiddle("zf3kabxcde224lkzf3mabxc51+crsdtzf3nab=", 3);
foreach (var record in result)
Console.WriteLine(record);