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

25th Dec 2019, 9:05 PM
Tamim Jabr
Tamim Jabr - avatar
2 Answers
+ 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++; } }
25th Dec 2019, 9:50 PM
Š„Š²Š³ŠµŠ½Ń–Š¹ Š”ŠµŃ€Ń–ŠŗŠ¾Ń‚
Š„Š²Š³ŠµŠ½Ń–Š¹ Š”ŠµŃ€Ń–ŠŗŠ¾Ń‚ - avatar
+ 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' ;
25th Dec 2019, 9:29 PM
Jayakrishna šŸ‡®šŸ‡³