So I'm jus tplaying around with arrays trying to get used to them. I decided to create a program that instead of counting the say, a's of text in a rich text box it will count the number of times any letter that appears in your code *of your choosing*.
first of all I'm pretty new to programming just a month or so.
So I figure the problem is in the actual count area, I just don't understand why the code counts every single char in the string instead of counting the char (charLetter1) that i tell it to count in the foreach statement. I tried many different things before I got this far and now I am just stuck on ideas.
I attached a picture of the type of results i'm getting.
first of all I'm pretty new to programming just a month or so.
So I figure the problem is in the actual count area, I just don't understand why the code counts every single char in the string instead of counting the char (charLetter1) that i tell it to count in the foreach statement. I tried many different things before I got this far and now I am just stuck on ideas.
public void letterToSearch()
{
char charLetter1;
string strLetter1;
// incase change array to char array ... { 'a', 'b', 'c', 'd', 'e', 'f' 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
string[] arrayAlphabet = new string[26] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
for (int i = 0; i < 26; ++i)
if (arrayAlphabet[i] == textboxLetter.Text)
{
strLetter1 = arrayAlphabet[i];
charLetter1 = char.Parse(strLetter1);
textboxLetterChosen.Text = charLetter1.ToString();
}
else { }
} //sets the character the user wants to search
public void countLetters()
{
int letterTotal = 0;
string inputText = textboxLetterCount.Text;
foreach (char charLetter1 in textboxLetterCount.Text)
{
letterTotal++;
}
countResultBox.Text = letterTotal.ToString();
} //counts and writes the number of letters in that area
private void btnShowgold_Click(object sender, EventArgs e)
{
showPlayersGold();
}
private void btnCountLetter_Click(object sender, EventArgs e)
{
letterToSearch();
countLetters();
}
I attached a picture of the type of results i'm getting.