Im creating a application that populates 30 textboxes with values based on the result of a word count.
the final version will have 30 words but this test ap i only include 3 of them
How wold you go about making this in to a loop?
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();
}
}
}