Sorting Information within a file

PhilBayley

Well-known member
Joined
Jan 10, 2003
Messages
69
Location
UK
HI,

Does anyone know of a c# class or any other component to sort data within a text file. I need to sort on multiple values and even hex codes on occasion. I used to use a dll called psortnt.dll from www.rrsd.com but it doesnt like c# or managed c++ and I am having difficulties.

Hopefully someone can help.

PB

ps. typical data would be

00000|0002|003|92380498ksdjflk|
00005|9283|299|lkdwke|kejfls|
00001|8734|203|jklflkjslkdj|kjdflksj

and I would sort by characters 0-5 for instance
 
Just a little note.

The files can be massive so loading it into memory is not really a good option.
 
ok - I have sorted my problem out but would still like to know of any other way of sorting data within a file without a third party product or a database.

fyi
The sort dll from rrsd.com was an old version and the new one works fine with .net (the old one works fine with c++). It is the fastest thing I have found to sort data within files.
 
Well, if I couldnt load the file to memory, Id probably try to do something like a bubble sort... something like this if you can understand what Im trying to do.
C#:
string Maximum, MatchLine, NetMaximum;
while (Counter != NumberOfLinesInFile) {
  Dat = "";
  MatchLine = "";
  Maximum = "";  
  while (SR.Peek != -1) {
    Dat = SR.ReadLine();
    if (Dat.Substring(0, 5).CompareTo(Maximum) > 0) {
      Maximum = Dat.Substring(0, 5);
      MatchLine = Dat;
    };
  };
  Counter++;
  SW.WriteLine(Dat);
};
 
Back
Top