0
How to access a string and count how many times a letter is repeated using c#?
https://www.sololearn.com/coach/54?ref=app I can't really figure it out how access a string and count if a letter is repeated It's very confusing that aint is 0 however the word I give contains "a" Please any suggestions or solutions? https://code.sololearn.com/cWjYa4OZ2TKc/?ref=app
2 odpowiedzi
+ 1
string Massive = Console.ReadLine();
int count = 0;
foreach (char sym in Massive )
{
count++; // lenght of string
}
int A = 0; // for store count of "a"
for (int i=0; i < count; i++)
{
if (Massive [i]=='a' ')
{
A++;
}
}
+ 1
Because your comparing a charecter with a string "a". You have to initialize it as a character.
'a' is different from "a".
char astring='a' ;