DotNet程序设计+词频软件

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

院/系:计算机科学学院课程名称:DotNet程序设计
一、程序源代码
using System;
using System.Collections;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace英语词频
{
public partial class Form1 : Form
{
public Form1()
{ InitializeComponent();
}
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream ;
StreamReader myReader;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "E:\\";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
//openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
string sLine;
myReader = File.OpenText(openFileDialog1 .FileName);
while ((sLine = myReader.ReadLine()) != null)
{
richTextBox1.Text += sLine;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.Text = "";
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
string W = richTextBox1.Text;
//定义一个字符数组
char[] c = { ' ', ',', '.', '?', '!', ':', ';', '\'', '\"' };
//分隔字符串后产生的字符串数组
string[] S = W.Split(c);
//建立哈希表
Hashtable ha = new Hashtable();
for ( int i = 0; i < S.Length; i++)
{
//判断文本是否进入
if (ha.ContainsKey(S[i]))
{
ha[S[i]] = (int)ha[S[i]] + 1;
}
else
{
ha.Add(S[i], 1);
}
}
//遍历哈希表
foreach (DictionaryEntry de in ha)
{
//输出
Console.WriteLine(de.Key + ":" + de.Value);
//追加文本
richTextBox2.AppendText(de.Key + ":" + de.Value + "\n");
}
int Sum=0;
for (int i = 0; i < S.Length; i++)
{
textBox1.Text = (i+1).ToString();
}
}
二、运行界面。

相关文档
最新文档