2021年3月6日星期六

I cannot seem to understand my current errors in this C# code for counting characters from an input field

**Below is my code, any help / recommendations would be helpful! Thanks in advance! I'm making a form that counts characters from an input field. I think I have most of it written correctly, but I'm coming up with a few errors... ** [This is the list of errors.][1]

using System;  using System.Collections.Generic;  using System.Linq;  using System.Data;  using System.ComponentModel;  using System.Drawing;  using System.Text;  using System.Threading.Tasks;  using System.Windows.Forms;    namespace Wk5Ch12Exer9  {      public partial class Form1 : Form      {          String inputText = null;          //How do I decide on below number?          int[] charFrequency = new int[52];            public Form1()          {              InitializeComponent();          }            private void richTextBox1_TextChanged(              object sender, EventArgs e)          {              inputText = rtbInputArea.Text;          }            private void processLine(String strng)          {              if (strng.Equals(null))                  return;              char[] current = strng.ToCharArray();                for (int idx = 0;                  idx < current.Length;                  idx++)              {                  try                  {                      if (current[idx]>= 65 &&                          current[idx] <= 90)                      {                          charFrequency[current[idx] - 65]                              += 1;                      }                      else if (current[idx] >=97 &&                          current[idx] <= 122)                      {                          charFrequency[current[idx] - 97                              + 26] += 1;                      }                  }                  catch (Exception)                  {                   }              }          }          private void button1_Click(object sender, EventArgs e)          {              StringBuilder output = new StringBuilder("");              String[] inp = inputText.Split('\n');              for (int idx = 0;                  idx < inp.Length;                  idx++)              {                  processLine(inp[idx]);              }              for (int ins = 0;                  ins < 26;                  ins++)              {                  if (charFrequency[ins] != 0)                  {                      output.Append("Frequency of " +                          (char)(ins + 65) + " is: " +                          charFrequency[ins] + "\n");                  }              }              for (int ins = 26;                  ins < charFrequency.Length;                  ins++)              {                  if (charFrequency[ins] != 0)                  {                      outputAppend("Frequency of " +                          (char)(ins + 97 - 26) +                          " is: " +                          charFrequency[ins] + "\n");                  }              }              rtbOutputArea.Text = output.ToString();          }          private void rtbOutputArea_TextChanged(              object sender, EventArgs e)          {            }          private void btnClear_Click(object sender,              EventArgs e)          {              rtbInputArea.Text = "";              rtbOutputArea_TextChanged.Text = "";              charFrequency = new int[52];          }      }  }  

I am truly so incredibly lost at what I am to do. I keep googling and just end up getting even more confused. [1]: https://i.stack.imgur.com/fPqaQ.png

https://stackoverflow.com/questions/66511982/i-cannot-seem-to-understand-my-current-errors-in-this-c-sharp-code-for-counting March 07, 2021 at 08:09AM

没有评论:

发表评论