PDA

View Full Version : تعداد تکرار کلمه ها موجود در یک فایل text



zare69
پنج شنبه 19 اسفند 1389, 08:33 صبح
دوستان سلام
من می خوام تعداد تکرار کلمه موجود تو یه فایل textبدست بیارم کسی میتونه به من کمک کنه خیلی حیاتی.
با تشکر:متفکر:

rainlover
پنج شنبه 19 اسفند 1389, 19:45 عصر
static void Main(string[] args)
{
string txt = "متن اصلی";
string statement = "عبارت مورد جستجو";
int count = 0;
int length=statement.Length;
while (txt.Contains(statement))
{
txt = txt.Remove(txt.IndexOf(statement), length);
count++;
}
Console.Write(count);
Console.ReadLine();
}

Saman_12
پنج شنبه 19 اسفند 1389, 21:05 عصر
شاید این منطقی نباشه :


private int GetNumofStr(string Sentence, string Str)
{

return Sentence.Split(Str.ToCharArray()).Length - 1;
}