Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. private void buttonAnalysis_Click(object sender, EventArgs e)
  2.         {
  3.             string text = textBox.Text;
  4.             Dictionary<char, int> result = new Dictionary<char, int>();
  5.  
  6.             foreach (var ch in chars)
  7.             {
  8.                 int count = 0;
  9.  
  10.                 for (int i = 0; i < textBox.Text.Length; i++)
  11.                 {
  12.                     if (text[i] == ch || text[i] == Char.ToUpper(ch))
  13.                         count++;
  14.                 }
  15.                 result.Add(ch, count);
  16.             }
  17.  
  18.             var sortedDict = from entry in result orderby entry.Key ascending select entry;
  19.  
  20.             textBoxOut.Clear();
  21.  
  22.             foreach (KeyValuePair<char, int> item in sortedDict)
  23.             {
  24.                 if(item.Value != 0)
  25.                     textBoxOut.AppendText(Char.ToUpper(item.Key) + ": " + item.Value + "\r\n");
  26.             }
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement