After reading many articles and methods I tried to create a write a easy method to counts in C# without sing nay in-built function like Split String or IsWhiteSpace.
There could be better ways than these lines of codes.
There could be better ways than these lines of codes.
using System;
class Program
{
static void Main()
{
int count = 0;
Console.Write(" Enter a string line : ");
string s1 = Console.ReadLine();
Console.WriteLine(s1);
int len=s1.Length;
for(int i=0;i<len;i++)
{
if(s1[i].Equals(' '))
{
count++;
Console.WriteLine("Count a found " + count );
}
}
Console.WriteLine("Total words " + (count +1));
Console.ReadLine();
}
}