How do I store a comma delimited file in an array sort it and display the contents in C#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a comma delimited file I have to import to an array then sort the data by LastName then state then find all those in a certain zip code however I can only display the first string with this program what am I doing wrong?
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
using





<span style="font-size:small <span style="font-size:small System;
<span style="font-size:small <span style="font-size:small <br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
using





<span style="font-size:small <span style="font-size:small System.Collections;
<span style="font-size:small <span style="font-size:small <br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
using





<span style="font-size:small <span style="font-size:small System.IO;
<span style="font-size:small <span style="font-size:small <br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
using





<span style="font-size:small <span style="font-size:small System.Collections.Generic;
<span style="font-size:small <span style="font-size:small <br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
using





<span style="font-size:small <span style="font-size:small System.Configuration;
<span style="font-size:small <span style="font-size:small <br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
using





<span style="font-size:small <span style="font-size:small System.Data;
<span style="font-size:small <span style="font-size:small <br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
using





<span style="font-size:small <span style="font-size:small System.Diagnostics;
<span style="font-size:small <span style="font-size:small <br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
using





<span style="font-size:small <span style="font-size:small System.Linq;
<span style="font-size:small <span style="font-size:small <br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
using





<span style="font-size:small <span style="font-size:small System.Text;
<span style="font-size:small <span style="font-size:small <br/>
<br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
namespace





<span style="font-size:small <span style="font-size:small IP4
<span style="font-size:small <span style="font-size:small
{




<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small class<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small GetEnumerator
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <br/>
<span style="font-size:small <span style="font-size:small
{




<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small class<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Program
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <br/>
<span style="font-size:small <span style="font-size:small
{




<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small static<span style="font-size:small <span style="font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small void<span style="font-size:small <span style="font-size:small Main()
<span style="font-size:small <span style="font-size:small
{
 





<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small //Reading topScore
<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <br/>
<span style="font-size:small <span style="font-size:small





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small string<span style="font-size:small <span style="font-size:small IP4Data =
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "C:\IP4 Data File_Revised.csv"<span style="font-size:small <span style="font-size:small ;
<span style="font-size:small <span style="font-size:small





<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ArrayList<span style="font-size:small <span style="font-size:small recordList =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ArrayList<span style="font-size:small <span style="font-size:small ();
<span style="font-size:small <span style="font-size:small





<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small //Process input file
<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <br/>
<span style="font-size:small <span style="font-size:small





<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small StreamReader<span style="font-size:small <span style="font-size:small readFile =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small StreamReader<span style="font-size:small <span style="font-size:small (IP4Data);
<span style="font-size:small <span style="font-size:small





<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small String<span style="font-size:small <span style="font-size:small [] splits;
<span style="font-size:small <span style="font-size:small





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small if<span style="font-size:small <span style="font-size:small (<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small File<span style="font-size:small <span style="font-size:small .Exists(IP4Data))
<span style="font-size:small <span style="font-size:small
{





<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small String<span style="font-size:small <span style="font-size:small record = readFile.ReadLine();
<span style="font-size:small <span style="font-size:small





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small while<span style="font-size:small <span style="font-size:small (record !=
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small null<span style="font-size:small <span style="font-size:small )
<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small //while record not empty.
<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <br/>
<span style="font-size:small <span style="font-size:small
{





<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Records<span style="font-size:small <span style="font-size:small myRecord =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Records<span style="font-size:small <span style="font-size:small ();
<span style="font-size:small <span style="font-size:small





<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small //Splits out parts and creates score objects
<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <br/>
<span style="font-size:small <span style="font-size:small
splits = record.Split(



<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small ,<span style="font-size:small <span style="font-size:small );
<span style="font-size:small <span style="font-size:small
myRecord.FirstName = splits[0];
myRecord.LastName = splits[1];
myRecord.Company = splits[2];
myRecord.Address = splits[3];
myRecord.City = splits[4];
myRecord.County = splits[5];
myRecord.State = splits[6];
myRecord.ZIP = splits[7];
myRecord.Phone = splits[8];
myRecord.Fax = splits[9];
myRecord.Email = splits[10];
myRecord.Web = splits[11];
 


recordList.Add(myRecord);
record = readFile.ReadLine();
 
recordList.Sort();





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small while<span style="font-size:small <span style="font-size:small (record !=
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small null<span style="font-size:small <span style="font-size:small )
<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small //while record not empty.
<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <br/>
<span style="font-size:small <span style="font-size:small
 
 
 
 





<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Console<span style="font-size:small <span style="font-size:small .WriteLine(record +
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "t"<span style="font-size:small <span style="font-size:small );
<span style="font-size:small <span style="font-size:small





<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Console<span style="font-size:small <span style="font-size:small .WriteLine();
<span style="font-size:small <span style="font-size:small





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small const<span style="font-size:small <span style="font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small int<span style="font-size:small <span style="font-size:small maxIndex
= 11;
<span style="font-size:small <span style="font-size:small





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small int<span style="font-size:small <span style="font-size:small index = 0;
<span style="font-size:small <span style="font-size:small





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small while<span style="font-size:small <span style="font-size:small (index < maxIndex)
<span style="font-size:small <span style="font-size:small
++index;
}
readFile.Close();
}
 
 
 
 
 
{
 
}
}
}
}
 
 
}
 
 

 
 


View the full article
 
Back
Top