C#统计单词词频
2013-04-23 16:27
330 查看
using System; using System.Collections; using System.ComponentModel; 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(); } }
相关文章推荐
- 统计大数据中的单词词频
- 单词统计小助(c#开源)
- 使用Python+NLTK实现英文单词词频统计
- C#通过正则表达式统计词频的一个方法
- linux shell 下载维基百科特色条目并统计单词词频
- 统计英文单词词频(c版)
- Linux Shell编程实战---统计特定文件中单词的词频
- 用Trie树实现词频统计和单词查询
- [置顶] 【spark 词频统计】spark单词进行计数升级版
- 语料中筛选出英文单词并统计词频,正则切割匹配
- java进行文本单词的词频统计
- Java 进行词频统计,并按单词顺序顺序排序
- 统计英文单词词频
- c++ 统计英文文本中每个单词的词频并且按照词频对每行排序
- Java词频统计算法(使用单词树)
- 编程统计一个英文文本文件中单词词频
- 个人和结对项目 - 英语单词词频统计
- 【学习笔记】C#中HashTable和快速排序的用法,从单词频率统计小程序写起
- 英文单词词频统计代码
- 英文单词词频统计