title: How to get data's from text file in c#
body: <p>I have a textile contains big amount of data ,first thing is i have to filter Leaf cell data which is scattered over there and here.For this  first line i filtered is line beginning with <code>ADD GCELL</code> which contains primary data,next what i have to do is i have to get the related data from the same text file by using <code>CELLID</code> coming in the same <code>ADD GCELL</code> line.Related datas are coming in the line beggining with <code>ADD GTRX</code> and  datas are <code>FREQ , TRXNO , ISMAINBCCH ,</code>.in nutshell <code>CELLID</code> is the common value for both line <code>ADD GCELL</code> and <code>ADD GTRX</code>. I have done few coding in c# , but i got stuck somewhere
  Here is  part of text file
  ...........................
  ...........................</p>
  
  <pre><code>ADD GCELL:CELLID=13, CELLNAME="NR_0702_07021_G1_A", MCC="424", MNC="02", LAC=6112, CI=7021, NCC=6, BCC=0, EXTTP=Normal_cell, IUOTP=Concentric_cell, ENIUO=ON, DBFREQBCCHIUO=Extra, FLEXMAIO=OFF, CSVSP=3, CSDSP=5, PSHPSP=4, PSLPSVP=6, BSPBCCHBLKS=1, BSPAGBLKSRES=4, BSPRACHBLKS=1, TYPE=GSM900_DCS1800, OPNAME="Tester", VIPCELL=NO
  ..............................
  ADD GTRX:TRXID=11140, TRXNAME="T_RAK_JaziratHamra_G_702_7021_A-0", FREQ=99, TRXNO=0, CELLID=13, IDTYPE=BYID, ISMAINBCCH=YES, ISTMPTRX=NO, GTRXGROUPID=80;
  </code></pre>
  
  <p>Code i have done is </p>
  
  <pre><code>using (StreamReader sr = File.OpenText(filename))
  {
      while ((s = sr.ReadLine()) != null)
      {
          if (s.Contains("ADD GCELL:"))
          {
              s = s.Replace("ADD GCELL:", "");
              string[] items = s.Split(',');
              foreach (string str in items)
              {
                  string[] str1 = str.Split('=');
                  if (str1[0] == "CELLID")
                  {
                      cellidnew = str1[1];
                  }
                  string fieldname = str1[0];
                  string value = str1[1].Replace(";", string.Empty).Replace("\"", string.Empty);
  
              }
  
              Getgtrxvalues(filename, ref cellname, ref cellidnew, ref Frequency, ref TRXNO ,ref ISMAINBCCH);
  
  
          }
      }
  }
  
  private static void Getgtrxvalues(string filename, ref string cellname, ref string cellid, ref int Frequency,  ref int TRXNO ,ref bool ISMAINBCCH)
  {
      using (StreamReader sr = File.OpenText(filename))
      {
          while ((s = sr.ReadLine()) != null)
          {
              if (s.Contains("ADD GTRX:"))
              {
                  try
                  {
  
  
  }
  }
  }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Everything working fine except one more condition i have to satisfy.Here for for ADD Gtrx: i am taking all values including Freq when ISMAINBCCH=YES ,but at the same time ISMAINBCCH=NO there are values for Freq which i have to get as comma seperated values.For example  Like here First i will take FREQ  where CELLID = 639(dynamic one anything can happen) and ISMAINBCCH=YES,that i have done now next task is i have to contenate FREQ values in a comma seperated way where CELLID=639 and ISMAINBCCH=NO, so here the output i want is 24,28,67 .How to achieve this one</p>
  
  <p>lines are</p>
  
  <pre><code> ADD GTRX:TRXID=0, TRXNAME="M_RAK_JeerExch_G_1879_18791_A-0", FREQ=81, TRXNO=0, CELLID=639, IDTYPE=BYID, ISMAINBCCH=YES, ISTMPTRX=NO, GTRXGROUPID=2556;
   ADD GTRX:TRXID=1, TRXNAME="M_RAK_JeerExch_G_1879_18791_A-1", FREQ=24, TRXNO=1, CELLID=639, IDTYPE=BYID, ISMAINBCCH=NO, ISTMPTRX=NO, GTRXGROUPID=2556;
   ADD GTRX:TRXID=5, TRXNAME="M_RAK_JeerExch_G_1879_18791_A-2", FREQ=28, TRXNO=2, CELLID=639, IDTYPE=BYID, ISMAINBCCH=NO, ISTMPTRX=NO, GTRXGROUPID=2556;
   ADD GTRX:TRXID=6, TRXNAME="M_RAK_JeerExch_G_1879_18791_A-3", FREQ=67, TRXNO=3, CELLID=639, IDTYPE=BYID, ISMAINBCCH=NO, ISTMPTRX=NO, GTRXGROUPID=2556;
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Finally i did it like shown below code</p>
  
  <p>i created one more property <code>DEFINED_TCH_FRQ = null</code> for getting concatenated string.But the problem is it is very slow .I am iterating text file two times ,first time is sr.readline() and second is for getting concatenated string by <code>File.Readline</code>(this aslo previously i used <code>File.Readalllines</code> and got out of memory exception)</p>
  
  <pre><code> List&lt;int&gt; intarr = new List&lt;int&gt;();
              intarr.Clear(); 
  var gtrx = new Gtrx
                              {
                                  CellId = int.Parse(PullValue(s, "CELLID")),
                                  Freq = int.Parse(PullValue(s, "FREQ")),
                                  TrxNo = int.Parse(PullValue(s, "TRXNO")),
                                  IsMainBcch = PullValue(s, "ISMAINBCCH").ToUpper() == "YES",
                                  Commabcch = new List&lt;string&gt; { PullValue(s, "ISMAINBCCH") },
                                  DEFINED_TCH_FRQ = null,
  
                                  TrxName = PullValue(s, "TRXNAME"),
  
                              };
  
   if (!intarr.Contains(gtrx.CellId))
                              {
  
                                  if (!_dictionary.ContainsKey(gtrx.CellId))
                                  {
                                      // No GCell record for this id. Do something!
                                      continue;
                                  }
                                  intarr.Add(gtrx.CellId);
                                  string results = string.Empty;
  
                                      var result = String.Join(",",
          from ss in File.ReadLines(filename)
          where ss.Contains("ADD GTRX:")
          where int.Parse(PullValue(ss, "CELLID")) == gtrx.CellId
          where PullValue(ss, "ISMAINBCCH").ToUpper() != "YES"
          select int.Parse(PullValue(ss, "FREQ")));
                                      results = result;
  
  
                                  var gtrxnew = new Gtrx
                                  {
                                      DEFINED_TCH_FRQ = results
                                  };
  
                                  _dictionary[gtrx.CellId].Gtrx = gtrx;
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Finally i did it like first i saved lines starting with ADD GTRX in to an array by using File.Readalllines and then used only that array to get concatenated string instead of storing entire text file and got some performance improvement.Now my question is if i convert my Text files each contain hundreds of thousands of lines in to xml and then retrieve data from xml file, will it make any performance improvement? if i use datatable and dataset rather than classes here will it make any performance improvement?</p>