<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'read a text file and perform some calcuation' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'read a text file and perform some calcuation' posted on the 'C#' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Thu, 20 Jun 2013 03:32:42 -0700</pubDate>
    <lastBuildDate>Thu, 20 Jun 2013 03:32:42 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>read a text file and perform some calcuation</title>
      <link>http://www.programmersheaven.com/mb/csharp/382889/382889/read-a-text-file-and-perform-some-calcuation/</link>
      <description>hi&lt;br /&gt;
&lt;br /&gt;
I have a problem on how to read text from file and perform operations on it for example&lt;br /&gt;
&lt;br /&gt;
i have this text file that include&lt;br /&gt;
&lt;br /&gt;
//name-//sex---------//birth //m1//m2//m3&lt;br /&gt;
&lt;br /&gt;
fofo, male,    1986, 67, 68,  69&lt;br /&gt;
momo, male,    1986, 99, 98,  100&lt;br /&gt;
Habs, female,  1988, 99, 100, 87&lt;br /&gt;
toto, male,    1989, 67, 68,  69&lt;br /&gt;
lolo, female,  1990, 89, 80,  87&lt;br /&gt;
soso, female,  1988, 99, 100, 83&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I want to read it and get the following&lt;br /&gt;
&lt;br /&gt;
avg m1 :  //average of all m1&lt;br /&gt;
avg m2 :  //average of all m2&lt;br /&gt;
avg m3 :  //average of all m3&lt;br /&gt;
avg Male M1 : //average of all m1 for males only&lt;br /&gt;
avg Male M2 : //average of all m2 for males only&lt;br /&gt;
avg Male M3 : //average of all m3 for males only&lt;br /&gt;
avg Female M1 : //average of all m1 for females only&lt;br /&gt;
avg Female M2 : //average of all m2 for females only&lt;br /&gt;
avg Female M3 : //average of all m3 for females only&lt;br /&gt;
&lt;br /&gt;
Its allwoed to use regular experssion and the system.IO&lt;br /&gt;
&lt;br /&gt;
can any one help&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/382889/382889/read-a-text-file-and-perform-some-calcuation/</guid>
      <pubDate>Thu, 11 Dec 2008 16:24:31 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: read a text file and perform some calcuation</title>
      <link>http://www.programmersheaven.com/mb/csharp/382889/383497/re-read-a-text-file-and-perform-some-calcuation/#383497</link>
      <description>Hey, assuming the text is always formatted that way you can use the following(using System.IO, System.Text.RegularExpressions, System.Collections.Generic) though you can do it while reading instead of sticking into a collection.&lt;br /&gt;
Code:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
List&amp;lt;Person&amp;gt; people = new List&amp;lt;Person&amp;gt;();
StreamReader test = new StreamReader(new FileStream("C:\\test.txt", FileMode.OpenOrCreate, FileAccess.Read));
while (test.Peek() != -1)
{
    Regex reg = new Regex(", ");
    object[] details = reg.Split(test.ReadLine());
    Person newPerson = new Person((String)details[0], (String)details[1], int.Parse((string)details[2]), int.Parse((string)details[3]),
        int.Parse((string)details[4]), int.Parse((string)details[5]));
    people.Add(newPerson);
}
foreach (Person pers in people)
{
    System.Console.WriteLine(pers.name);
}
&lt;/pre&gt;&lt;br /&gt;
and the Person Class is:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
public String name, sex;
public int birth, m1, m2, m3;

public Person(String name, String sex, int birth, int m1, int m2, int m3)
{
    this.name = name;
    this.sex = sex;
    this.birth = birth;
    this.m1 = m1;
    this.m2 = m2;
    this.m3 = m3;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
The storage will allow you to do things with it after like sorting, searching, etc. In that last foreach you do w/e calculations you want - just have a variable(or several) initialized outside the loop to keep track.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/382889/383497/re-read-a-text-file-and-perform-some-calcuation/#383497</guid>
      <pubDate>Wed, 24 Dec 2008 15:36:59 -0700</pubDate>
      <category>C#</category>
    </item>
  </channel>
</rss>