25 lines
884 B
C#
25 lines
884 B
C#
namespace _10_4
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
string text = @"The quick brown fox jumps over the lazy dog." +
|
|
@"An apple a day keeps the doctor away." +
|
|
@"Can a fox and a dog be friends?";
|
|
Console.WriteLine(text);
|
|
string searchTerm = "the";
|
|
string[] source = text.ToLower().Split(new char[] { '.', ' ','!','?','.' }, StringSplitOptions.RemoveEmptyEntries);
|
|
int wordCount = 0;
|
|
foreach (string s in source)
|
|
{
|
|
if (s.CompareTo(searchTerm)==0)
|
|
{
|
|
wordCount++;
|
|
}
|
|
}
|
|
Console.WriteLine("单词{0}一共出现{1}次,频率{2:#0.##%}",searchTerm,wordCount,wordCount/(double)source.Length);
|
|
}
|
|
}
|
|
}
|