using System;
using System.IO;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] words = new string[6] { "stripos", "click", "substr", "save", "search", "sizeof" };
int[] count = Enumerable.Repeat(0, 6).ToArray();
string line, fileName = "d:\\url.php";
using (StreamReader file = new StreamReader(fileName))
{
while ((line = file.ReadLine()) != null)
{
for (int i = 0; i < 6; i++)
{
string[] source = line.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',',
'<', '>', '/', '$', '[', ']', '(', ')',
'=', '\\', '_', '"', '-' },
StringSplitOptions.RemoveEmptyEntries);
var matchQuery = from word in source
where word.ToLowerInvariant() == words[i].ToLowerInvariant()
select word;
count[i] = count[i] + matchQuery.Count();
}
}
}
for (int i = 0; i < 6; i++)
Console.WriteLine("The word: {0,-10} appear {1,3} times in file: {2}", words[i], count[i],
fileName);
}
}
}
/*
run:
The word: stripos appear 5 times in file: d:\url.php
The word: click appear 50 times in file: d:\url.php
The word: substr appear 14 times in file: d:\url.php
The word: save appear 4 times in file: d:\url.php
The word: search appear 7 times in file: d:\url.php
The word: sizeof appear 2 times in file: d:\url.php
*/