Count The Particular Word?????

Sabarimahesh
Posted by Sabarimahesh under C# category on | Points: 40 | Views : 1882
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
public static class Program
{
static void Main(string[] args)
{


string Searchword = "a";
string SearchString = "sabarimahesh";
List<int> Total_cnt = Search_key(Searchword, SearchString);

Console.WriteLine(Total_cnt.Count.ToString(), "Matches");


Console.ReadLine();


}




public static List<int> Search_key(string Tg, string Sub)
{
List<int> Reslt = new List<int>();
for (int i = 0; i < (Sub.Length - Tg.Length) + 1; i++)
{
if (Sub.Substring(i, Tg.Length) == Tg) Reslt.Add(i);
}
return Reslt;
}

}
}


output
3

Comments or Responses

Login to post response