0
我創建了一個應用程序,該應用程序使用基於單詞計數結果的值填充30個文本框。基於30個用戶創建一個循環?
最終版本將有30個字,但這個測試AP我只包括其中的3
如何WOLD你去使這在一個循環?
int[] totX = new int[30];
string nav1 = "test1";
string nav2 = "test2";
string nav3 = "test3";
public Form1()
{
using (StreamReader sr = new StreamReader(@"c:\temp\output.txt"))
{
var total = 0;
while (!sr.EndOfStream)
{
var counts = sr
.ReadLine()
.Split('"')
.GroupBy(s => s)
.Select(g => new { Word = g.Key, Count = g.Count() });
var wc = counts.SingleOrDefault(c => c.Word == nav1);
total += (wc == null) ? 0 : wc.Count;
totX[0] = total;
}
}
using (StreamReader sr = new StreamReader(@"c:\temp\output.txt"))
{
var total = 0;
while (!sr.EndOfStream)
{
var counts = sr
.ReadLine()
.Split('"')
.GroupBy(s => s)
.Select(g => new { Word = g.Key, Count = g.Count() });
var wc = counts.SingleOrDefault(c => c.Word == nav2);
total += (wc == null) ? 0 : wc.Count;
totX[1] = total;
}
}
using (StreamReader sr = new StreamReader(@"c:\temp\output.txt"))
{
var total = 0;
while (!sr.EndOfStream)
{
var counts = sr
.ReadLine()
.Split('"')
.GroupBy(s => s)
.Select(g => new { Word = g.Key, Count = g.Count() });
var wc = counts.SingleOrDefault(c => c.Word == nav3);
total += (wc == null) ? 0 : wc.Count;
totX[2] = total;
}
}
InitializeComponent();
}
private void button1_Click_1(object sender, EventArgs e)
{
textBox1.Text = totX[0].ToString();
textBox2.Text = totX[1].ToString();
textBox3.Text = totX[2].ToString();
}
}
}
什麼類型的文件是嗎?內容是什麼樣的? – shahkalpesh 2009-09-15 17:19:19
這是一個很長的日誌文件,,,繼續隱含的字符串與「分離真正的單詞。後面的單詞是字符串中的用戶名。 – Darkmage 2009-09-15 18:23:34