using System.Collections.Generic;
public class PatternLength
public int qty { get; set; }
public string characters { get; set; }
public static void Main()
string ret = string.Empty;
Console.WriteLine("Enter String(Field can not be empty): ");
str = Console.ReadLine();
if (String.IsNullOrEmpty(str))
Console.WriteLine("The String field is empty!");
Console.WriteLine("Enter Pattern Length(Field can not be empty and must be an integer): ");
Verlength = Console.ReadLine();
if (String.IsNullOrEmpty(Verlength))
Console.WriteLine("The Pattern Length field is empty!");
length = Convert.ToInt32(Verlength);
Console.WriteLine("Please enter an integer number in the Pattern Length field!");
Console.WriteLine("The length of the string can not be less than Patter Length!");
var PatternLengths = new List<PatternLength>();
if (str.Length == length)
PatternLengths.Add(new PatternLength { qty = 1, characters = str });
for (int i = 0; i <= str.Length - length; i++)
ret = str.Substring(i, length);
PatternLengths.Add(new PatternLength { qty = 1, characters = ret });
for (int i = 0; i < str.Length - length; i++)
ret = str.Substring(i, length);
PatternLengths.Add(new PatternLength { qty = 1, characters = ret });
from PatternLength in PatternLengths
group PatternLength by PatternLength.characters into PatternLengthGroup
characters = PatternLengthGroup.Key,
Totalqty = PatternLengthGroup.Sum(x => x.qty),
foreach (var item in Totals)
Console.WriteLine("Occurrences: " + item.characters + " - " + item.Totalqty.ToString());
Console.WriteLine("There are no occurrences !");
Console.WriteLine("There are no occurrences !");