|
|
#1 |
|
New Member
Join Date: Jan 07
Posts: 9
![]() |
[02/03] Problem Sorting 2 D Array
I have a log file that I am trying to parse out and sort. Eventually i will print it out into xml. I have already pulled the file out of the log and read it into memory, i have also parsed the log file into a two dimensional array to be able to sort it. The reason i have to parse and put into a two d array is because of this:
07-01-15 00:00:00 00116: < RCPT TO:<email@eamil.com> 07-01-15 00:00:00 00120: Connection opened by pool-55-555-55-55. <blah> 07-01-15 00:00:00 00116: > 551 user does not exist If you see in the file the third set of numbers is out of order. 00116 00120 00116 So what i have done is put those values into one side of the array and put the rest of the file into the other side. I now want to sort on column 0 and then write it back out to the file. This is what the array would look like: 00116 | 07-01-15 00:00:00 00116: < RCPT TO:<email@eamil.com> 00120 | 07-01-15 00:00:00 00120: Connection opened by pool-55-555-55-5 00116 | 07-01-15 00:00:00 00116: > 551 user does not exist The result would look like: 00116 | 07-01-15 00:00:00 00116: < RCPT TO:<email@eamil.com> 00116 | 07-01-15 00:00:00 00116: > 551 user does not exist 00120 | 07-01-15 00:00:00 00120: Connection opened by pool-55-555-55-5 The Code: This function Reads the file in and splits it into the two d array: VB Code:
This is the Quick Sort to sort the two d array: VB Code:
Swap Rows Used by QuickSort: VB Code:
Print New Array. This is where i am getting an error it looks like the array getting passed to this function isn't created correctly or filling it. VB Code:
|
|
|
|
|
|
#2 |
|
Frenzied Member
Join Date: Jan 02
Location: Joburg, RSA
Posts: 1,722
![]() ![]() ![]() |
Re: [02/03] Problem Sorting 2 D Array
You could save yourself a lot of code...
First off - I don't have VB installed, so the code sample will be in C#. The code makes use of the System.Collections.IComparer interface to compare two values - in this case, the string arrays. To do the actual sorting, the Array.Sort method has an overload that accepts an IComparer. The comparer: PHP Code:
PHP Code:
|
|
|
|
|
|
#3 |
|
Frenzied Member
Join Date: Jun 06
Location: UK
Posts: 1,745
![]() ![]() ![]() |
Re: [02/03] Problem Sorting 2 D Array
Maybe this isn't very accurate or even something you want to explore but why don't you put the numbers at the beginning of the string?? Load them into a list and use the Sort method that comes with it? You may want to check this out. I don't know if it would always be correct but maybe you could adapt it to help.
VB Code:
|
|
|
|
|
|
#4 |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,422
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [02/03] Problem Sorting 2 D Array
With the text format you have in the text file and what you want to do, I think just a 1-d string array will get the job done.
Try this: VB Code:
|
|
|
|
|
|
#5 | |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,422
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [02/03] Problem Sorting 2 D Array
Quote:
Oopssss.... He's using [02/03] so List isn't an option... To Pricejt: Regarding Stimbo code, you would use an Arraylist instead of List in [02/03] |
|
|
|
|
|
|
#6 |
|
New Member
Join Date: Jan 07
Posts: 9
![]() |
Re: [02/03] Problem Sorting 2 D Array
Thank you guys for all your feedback. axion_sa I am not very good with C# so dont know how easy that will be for me.
Stanav I tried implimenting your code but it didn't sort it. I am thinking that its not spliting on the right part of the file. stimbo: I dont know about your method The log file i have probably has somewhere around 64,000 lines that i would have to loop through and add. But i don tkonw maybe that is the best way. |
|
|
|
|
|
#7 |
|
Frenzied Member
Join Date: Jun 06
Location: UK
Posts: 1,745
![]() ![]() ![]() |
Re: [02/03] Problem Sorting 2 D Array
Ooopps indeed, I didn't even see the 02/03.
If there is that many lines then ICompare would definitely be better. There's a really nice example of it (ICompare) somewhere on this forum. Do a search for it and you will probably come across it. I think one of the moderators posted it. You should be able to adapt it from that. |
|
|
|
|
|
#8 | |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,422
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [02/03] Problem Sorting 2 D Array
Quote:
Try replacing this line VB Code:
VB Code:
|
|
|
|
|
|
|
#9 |
|
New Member
Join Date: Jan 07
Posts: 9
![]() |
Re: [02/03] Problem Sorting 2 D Array
Stanav: you are right that worked. However with the 64,000 lines it is very slow. Do you think that the iCompare would be a lot faster than this way?
|
|
|
|
|
|
#10 |
|
Frenzied Member
Join Date: Jan 02
Location: Joburg, RSA
Posts: 1,722
![]() ![]() ![]() |
Re: [02/03] Problem Sorting 2 D Array
**sigh
http://www.kamalpatel.net/ConvertCSharp2VB.aspx VB Code:
VB Code:
|
|
|
|
|
|
#11 |
|
New Member
Join Date: Jan 07
Posts: 9
![]() |
Re: [02/03] Problem Sorting 2 D Array
Ok Stanav: I take that back it work really fast but the probelm is it dosen't sort it all correctly.
07-01-15 00:00:00 00116: 07-01-15 00:00:00 00116: 07-01-15 00:00:00 00120: 07-01-15 00:00:01 00109: 07-01-15 00:00:01 00109: 07-01-15 00:00:01 00116: 07-01-15 00:00:01 00116: 07-01-15 00:00:02 00109: 07-01-15 00:00:02 00109: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:02 00120: 07-01-15 00:00:05 00109: 07-01-15 00:00:05 00109: 07-01-15 00:00:05 00119: 07-01-15 00:00:05 00120: 07-01-15 00:00:06 00121: 07-01-15 00:00:07 00119: 07-01-15 00:00:07 00119: 07-01-15 00:00:07 00119: 07-01-15 00:00:07 00120: 07-01-15 00:00:07 00120: 07-01-15 00:00:07 00120: You can see that it sorted them all but i need it to ignore the second set of numbers the "00:00:07" and just sort on that third set. Maybe concatinate the third number onto the front of the string. but i guess it would still compare the 2nd number too. ex. 00109 is all over the place in this file Last edited by pricejt; Jan 25th, 2007 at 02:37 PM. |
|
|
|
|
|
#12 | |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,422
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [02/03] Problem Sorting 2 D Array
Quote:
|
|
|
|
|
|
|
#13 |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,422
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [02/03] Problem Sorting 2 D Array
Try this now... I didn't test it (because I don't have the text file), but it should work though.
VB Code:
Last edited by stanav; Jan 25th, 2007 at 03:48 PM. |
|
|
|
|
|
#14 |
|
New Member
Join Date: Jan 07
Posts: 9
![]() |
Re: [02/03] Problem Sorting 2 D Array
I got the original one working by just parsing the thrid number to the front but when we threw an even bigger file at it we had memory errors.
I then tried the function you just sent and it threw an error that length cannot be less than zero Guy im making this for also gave me a new requirement haha. After it groups those third numbers together it then has to order it by the second number which is a time code. Oh the joy. |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|