using System;
class HelloWorld
{
static void Main(String[] args)
{
countSearchCharInInString("Stanley",'s'); //return 1
}
//inString = "Stanley", searchChar = 't', return 1
static int countSearchCharInInString(string inString, char searchChar)
{
foreach (char letter in countSearchCharInInString
{
for (int i = 0; i = inString.lengeth; i++)
{
string count = inString{i}
if (count = searchChar)
string newString = [];
newString.Add(count);
console.writeline(newString.length)
}
};
return 0;
}
}
I am trying to count how many times the letter s is present in this string name Stanley. I havent used c# in a while and was wondering if there was ashorter way of doing this. Also, this doesn't work I know but it was just me brainstorming the concept. Any help would be greatly appreciated.