Link to home
Start Free TrialLog in
Avatar of williepriester
williepriesterFlag for United States of America

asked on

Best way to sort data using two keys.

Hello experts,

I am trying to figure out the best way to read in a large amount of data from a text file and then sort it using two keys. I have found many examples of sorting multidimensional arrays using a single key but not two keys. I have seen suggestions for using lists, tuples and datasets but still nothing on how to sort with two keys.

The text file I read in will typically have about 80 to 90 header records and then anywhere from 2000 to over 1000000 lines of data. I need to get four data items from each line.

Line# is in columns 2-5 and is an integer
Station# is in columns 22-25 and is an integer
Xcoord is in columns 47-55 and is a double
Ycoord is in columns 56-65 and is a double

Sample.txt

Once the data is loaded I need to sort by Line# as the first key and Station# as the second key.

So which is the best way to do this? Multidimension array? Lists? Tuples? Datasets? Datatable?

I did try to do it using a datagridview but it was taking way to long to load the data from a file with 650000 records.

Thanks in advance for any help that I can get.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi williepriester;

Can I assume that lines beginning in column one with an H our headers and lines with R in column one are the lines you are interested in?
Avatar of williepriester

ASKER

Hi Fernando,

Yes that is correct, the headers have an "H" and the data records will have an "r" or an "S".
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Fernando, this is exactly what I have been looking for.
Not a problem williepriester, glad to help.