Results 1 to 14 of 14

Thread: [02/03] Problem Sorting 2 D Array

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    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 protected]>
    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 protected]>
    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 protected]>
    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:
    1. Private Function OrderFile(ByVal fileLocation As String)
    2.         Dim fs As System.IO.FileStream
    3.         Dim sr As StreamReader
    4.         Try
    5.  
    6.             'We have our variables, lets attempt to open it  
    7.             fs = New System.IO.FileStream(fileLocation, _
    8.                 FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite)
    9.  
    10.         Catch
    11.  
    12.             'Make sure that it exists, and if it doesn't display an error  
    13.             MessageBox.Show("Count not open the file.  Make sure '" & fileLocation & _
    14.                 "' exists in the location shown.")
    15.  
    16.         Finally
    17.  
    18.             'It works, but we are going to try one last method  
    19.             If fs.CanRead = True Then
    20.                 'This is where we would read from the file  
    21.                 txtFileDisplay.Text = "File opened!"
    22.  
    23.                 'We are done with the file now, so close it  
    24.                 fs.Close()
    25.             End If
    26.  
    27.         End Try
    28.  
    29.         ''Create the StreamReader and associate the filestream with it  
    30.         Dim myReader As New System.IO.StreamReader(fileLocation)
    31.  
    32.         ''Read the entire text, and set it to a string  
    33.         Dim sFileContents As String = myReader.ReadToEnd()
    34.  
    35.         ''Print it to the textbox  
    36.         txtFileDisplay.Text = sFileContents
    37.  
    38.         ''Close everything when you are finished  
    39.         myReader.Close()
    40.  
    41.  
    42.  
    43.         ' Split file data into array of lines
    44.             Dim textReader As New System.IO.StreamReader(fileLocation)
    45.             Dim WholeLine As String
    46.         Dim lines(,) As String
    47.         Dim r As Integer
    48.         Dim Count = 0 '
    49.         WholeLine = textReader.ReadLine()
    50.         While Not WholeLine.Length <= 0
    51.  
    52.             ReDim Preserve lines(1, Count)
    53.             lines(0, Count) = WholeLine.Substring(18, 5)
    54.             r = WholeLine.Length
    55.             lines(1, Count) = WholeLine.Substring(0, r)
    56.             Count = Count + 1
    57.             WholeLine = textReader.ReadLine()
    58.  
    59.         End While
    60.  
    61.  
    62.         Call QuickSort(lines, 0, 0, 0)
    63.  
    64.  
    65.     End Function

    This is the Quick Sort to sort the two d array:

    VB Code:
    1. Sub QuickSort(ByVal vec, ByVal loBound, ByVal hiBound, ByVal SortField)
    2.  
    3.         '==--------------------------------------------------------==
    4.         '== Sort a 2 dimensional array on SortField                ==
    5.         '==                                                        ==
    6.         '== This procedure is adapted from the algorithm given in: ==
    7.         '==    ~ Data Abstractions & Structures using C++ by ~     ==
    8.         '==    ~ Mark Headington and David Riley, pg. 586    ~     ==
    9.         '== Quicksort is the fastest array sorting routine for     ==
    10.         '== unordered arrays.  Its big O is  n log n               ==
    11.         '==                                                        ==
    12.         '== Parameters:                                            ==
    13.         '== vec       - array to be sorted                         ==
    14.         '== SortField - The field to sort on (2nd dimension value) ==
    15.         '== loBound and hiBound are simply the upper and lower     ==
    16.         '==   bounds of the array's 1st dimension.  It's probably  ==
    17.         '==   easiest to use the LBound and UBound functions to    ==
    18.         '==   set these.                                           ==
    19.         '==--------------------------------------------------------==
    20.  
    21.         Dim pivot(), loSwap, hiSwap, temp, counter
    22.         ReDim pivot(UBound(vec, 2))
    23.         loSwap = LBound(vec)
    24.         hiSwap = UBound(vec, 2)
    25.         '== Two items to sort
    26.         If hiBound - loBound = 1 Then
    27.             If vec(loBound, SortField) > vec(hiBound, SortField) Then Call SwapRows(vec, hiBound, loBound)
    28.         End If
    29.  
    30.         '== Three or more items to sort
    31.  
    32.         For counter = 0 To UBound(vec, 2)
    33.             pivot(counter) = vec(Int((loBound + hiBound) / 2), counter)
    34.             vec(Int((loBound + hiBound) / 2), counter) = vec(loBound, counter)
    35.             vec(loBound, counter) = pivot(counter)
    36.         Next
    37.  
    38.         loSwap = loBound + 1
    39.         hiSwap = hiBound
    40.  
    41.         Do
    42.             '== Find the right loSwap
    43.             While loSwap < hiSwap And vec(loSwap, Int(SortField)) <= pivot(SortField)
    44.                 loSwap = loSwap + 1
    45.             End While
    46.             '== Find the right hiSwap
    47.             While vec(hiSwap, SortField) > pivot(Int(SortField))
    48.                 hiSwap = hiSwap - 1
    49.             End While
    50.             '== Swap values if loSwap is less then hiSwap
    51.             If loSwap < hiSwap Then Call SwapRows(vec, loSwap, hiSwap)
    52.  
    53.  
    54.         Loop While loSwap < hiSwap
    55.  
    56.         For counter = 0 To UBound(vec, 2)
    57.             vec(loBound, counter) = vec(hiSwap, counter)
    58.             vec(hiSwap, counter) = pivot(counter)
    59.         Next
    60.  
    61.         '== Recursively call function .. the beauty of Quicksort
    62.         '== 2 or more items in first section
    63.         If loBound < (hiSwap - 1) Then Call QuickSort(vec, loBound, hiSwap - 1, Int(SortField))
    64.         '== 2 or more items in second section
    65.         If hiSwap + 1 < hiBound Then Call QuickSort(vec, hiSwap + 1, hiBound, Int(SortField))
    66.  
    67.         Call PrintArray(pivot, 0, 0)
    68.     End Sub  'QuickSort

    Swap Rows Used by QuickSort:
    VB Code:
    1. Sub SwapRows(ByVal ary, ByVal row1, ByVal row2)
    2.         '== This proc swaps two rows of an array
    3.         Dim x, tempvar
    4.         For x = 0 To UBound(ary, 2)
    5.             tempvar = ary(row1, x)
    6.             ary(row1, x) = ary(row2, x)
    7.             ary(row2, x) = tempvar
    8.         Next
    9.     End Sub  'SwapRows

    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:
    1. Sub PrintArray(ByVal vec, ByVal lo, ByVal hi)
    2.         '==-----------------------------------------==
    3.         '== Print out an array from the lo bound    ==
    4.         '==  to the hi bound.                       ==
    5.         '==                                         ==
    6.         '==-----------------------------------------==
    7.         Dim sw As StreamWriter = File.CreateText("input.txt")
    8.         Dim i, j
    9.         lo = LBound(vec)
    10.         hi = UBound(vec)
    11.         For i = lo To hi
    12.             For j = 0 To UBound(vec)
    13.                 sw.Write(vec(i, j))
    14.             Next
    15.         Next
    16.  
    17.         sw.Close()
    18.     End Sub  'PrintArray

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    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:
        /// <summary>
        /// Can be used by the Array.Sort method to sort string array values by a specified index.
        /// </summary>
        
    public class StringArrayComparerIComparer
        
    {
            private 
    int _compareIndex;

            
    /// <summary>
            /// Gets or sets the array index that will be used to sort.
            /// </summary>
            
    public int CompareIndex
            
    {
                
    get { return _compareIndex; }
                
    set _compareIndex value; }
            }

            
    /// <summary>
            /// Compares the values at the <see cref="CompareIndex"/> index.
            /// </summary>
            /// <remarks>Assumes the <paramref name="x" /> and <paramref name="y" /> parameters are string arrays.</remarks>
            /// <param name="x"></param>
            /// <param name="y"></param>
            /// <returns></returns>
            
    public int Compare(object xobject y)
            {
                
    string[] xValues = (string[]) x;
                
    string[] yValues = (string[]) y;
                
                return (
    xValues[this.CompareIndex].CompareTo(yValues[this.CompareIndex]));
            }
        } 
    The test code:
    PHP Code:
        /// <summary>
        /// Summary description for Class1.
        /// </summary>
        
    class Class1
        
    {
            
    /// <summary>
            /// The main entry point for the application.
            /// </summary>
            
    [STAThread]
            static 
    void Main(string[] args)
            {
                
    string[][] values = new string[][]
                    {
                        new 
    string[] {"0105""Pom"},
                        new 
    string[] {"0015""Foo"},
                        new 
    string[] {"0016""Abc"},
                        new 
    string[] {"0012""Lkj"},
                        new 
    string[] {"0001""Tyu"}
                    };
                
                
    StringArrayComparer comparer = new StringArrayComparer();
                
    comparer.CompareIndex 0;
                
                Array.
    Sort(valuescomparer);
                
                for (
    int i 0values.Lengthi++)
                {
                    
    Console.Write("Row [{0}]: "i.ToString());
                    for (
    int j 0values[i].Lengthj++)
                        
    Console.Write("{0}\t"values[i][j]);
                    
    Console.Write("\n");
                }
                
                
    Console.WriteLine("\nDone!");
                
    Console.ReadLine();
            }
        } 

  3. #3
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    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:
    1. Dim myString As New List(Of String)
    2.         myString.Add("02323: 07-01-16 00:00:00: < RCPT TO:<[email protected]>")
    3.         myString.Add("00116: 07-01-15 00:00:00: < RCPT TO:<[email protected]>")
    4.         myString.Add("00120: 07-01-15 00:00:00: Connection opened by pool-55-555-55-55. <blah>")
    5.         myString.Add("00116: 07-01-15 00:00:00: > 551 user does not exist")
    6.  
    7.         myString.Sort()
    8.  
    9.         ListBox1.Items.AddRange(myString.ToArray)
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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:
    1. 'Open the file & read all the contents
    2. Dim reader As IO.StreamReader = IO.File.OpenText("path here")
    3.         Dim strContent As String = reader.ReadToEnd
    4.         reader.Close()
    5.         'Split the file contents by line to an array then sort it
    6.         Dim lines() As String = strContent.Split(ChrW(13))
    7.         Array.Sort(lines)
    8.         'Write back to the file
    9.         Dim writer As IO.StreamWriter = IO.File.CreateText("path here")
    10.         For i As Integer = 0 To lines.GetUpperBound(0)
    11.             writer.WriteLine(lines(i))
    12.         Next
    13.         writer.Close()

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [02/03] Problem Sorting 2 D Array

    Quote Originally Posted by stimbo
    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:
    1. Dim myString As New List(Of String)
    2.         myString.Add("02323: 07-01-16 00:00:00: < RCPT TO:<[email protected]>")
    3.         myString.Add("00116: 07-01-15 00:00:00: < RCPT TO:<[email protected]>")
    4.         myString.Add("00120: 07-01-15 00:00:00: Connection opened by pool-55-555-55-55. <blah>")
    5.         myString.Add("00116: 07-01-15 00:00:00: > 551 user does not exist")
    6.  
    7.         myString.Sort()
    8.  
    9.         ListBox1.Items.AddRange(myString.ToArray)
    To Stimbo:
    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. #6

    Thread Starter
    New Member
    Join Date
    Jan 2007
    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. #7
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    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.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [02/03] Problem Sorting 2 D Array

    Quote Originally Posted by pricejt
    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.
    That could be because the lines in your text file are terminated with a new line character instead of a cartridge return character.
    Try replacing this line
    VB Code:
    1. Dim lines() As String = strContent.Split(ChrW(13))
    With these lines and see if it works
    VB Code:
    1. Dim seperators As Char() = {ChrW(10), ChrW(13)}
    2. Dim lines() As String = strContent.Split(seperators)

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2007
    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. #10
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: [02/03] Problem Sorting 2 D Array

    **sigh

    http://www.kamalpatel.net/ConvertCSharp2VB.aspx

    VB Code:
    1. Public Class StringArrayComparer
    2.      Implements IComparer
    3.         Private _compareIndex As Integer
    4.  
    5.         Public Property CompareIndex() As Integer
    6.             Get
    7.                  Return _compareIndex
    8.             End Get
    9.             Set (ByVal Value As Integer)
    10.                  _compareIndex = value
    11.             End Set
    12.         End Property
    13.  
    14.         Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
    15.             Dim xValues() As String = CType(x, String())
    16.             Dim yValues() As String = CType(y, String())
    17.  
    18.             Return (xValues(Me.CompareIndex).CompareTo(yValues(Me.CompareIndex)))
    19.         End Function
    20.     End Class
    21.  
    22. '----------------------------------------------------------------
    23. ' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
    24. ' Developed by: Kamal Patel ([url]http://www.KamalPatel.net[/url])
    25. '----------------------------------------------------------------

    VB Code:
    1. 'Error: Converting Properties
    2.  
    3.     Class Class1
    4.         <STAThread> _
    5.         Shared  Sub Main(ByVal args() As String)
    6.             Dim values()() As String =  New String()() {New String(){"0105", "Pom"}
    7. ,
    8.                     New String()
    9.                     {
    10.                         "0015", "Foo"
    11.                     }
    12. ,
    13.                     New String()
    14.                     {
    15.                         "0016", "Abc"
    16.                     }
    17. ,
    18.                     New String()
    19.                     {
    20.                         "0012", "Lkj"
    21.                     }
    22. ,
    23.                     New String()
    24.                     {
    25.                         "0001", "Tyu"
    26.                     }
    27.                 }
    28.  
    29.  
    30.             Dim comparer As StringArrayComparer =  New StringArrayComparer()
    31.             comparer.CompareIndex = 0
    32.  
    33.             Array.Sort(values, comparer)
    34.  
    35.             Dim i As Integer
    36.             For  i = 0 To  values.Length- 1  Step  i + 1
    37.                 Console.Write("Row [{0}]: ", i.ToString())
    38.                     Dim j As Integer
    39.                     For  j = 0 To  values(i).Length- 1  Step  j + 1
    40.                         Console.Write("{0}\t", values(i)(j))
    41.                     Next
    42.                 Console.Write("\n")
    43.             Next
    44.  
    45.             Console.WriteLine("\nDone!")
    46.             Console.ReadLine()
    47.         End Sub
    48.     End Class
    49.  
    50. '----------------------------------------------------------------
    51. ' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
    52. ' Developed by: Kamal Patel ([url]http://www.KamalPatel.net[/url])
    53. '----------------------------------------------------------------

  11. #11

    Thread Starter
    New Member
    Join Date
    Jan 2007
    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 03:37 PM.

  12. #12
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [02/03] Problem Sorting 2 D Array

    Quote Originally Posted by pricejt
    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
    With a little manipulation, you can get it to sort the way you want... Otherwise, just give me a few minutes to fix it

  13. #13
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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:
    1. Private Function Foo(ByVal strInputFilePath As String, Optional ByVal strOutputFilePath As String = "") As Boolean
    2.         Try
    3.             'Open the file & read all the contents
    4.             Dim reader As IO.StreamReader = IO.File.OpenText(strInputFilePath)
    5.             Dim strContent As String = reader.ReadToEnd
    6.             reader.Close()
    7.  
    8.             'Split the file contents by line to an array then sort it
    9.             Dim seperators As Char() = {Chr(10), Chr(13)}
    10.             Dim temps() As String = strContent.Split(seperators)
    11.  
    12.             Dim strBldr As New System.Text.StringBuilder
    13.             Dim i As Integer = 0
    14.             For i = 0 To temps.GetUpperBound(0)
    15.                 If temps(i).Trim().Length >= 23 Then
    16.                     strBldr.Append(temps(i).Substring(18, 5) & temps(i) & ChrW(13))
    17.                 End If
    18.             Next
    19.  
    20.             Dim lines() As String = strBldr.ToString.Split(seperators)
    21.             Array.Sort(lines)
    22.             'Write back to the file
    23.             Dim outputPath As String = strInputFilePath
    24.             If strOutputFilePath <> "" Then
    25.                 outputPath = strOutputFilePath
    26.             End If
    27.             Dim writer As IO.StreamWriter = IO.File.CreateText(outputPath)
    28.             For i = 0 To lines.GetUpperBound(0)
    29.                 writer.WriteLine(lines(i).Substring(5))
    30.             Next
    31.             writer.Close()
    32.         Catch ex As Exception
    33.             MsgBox(ex.Message)
    34.             Return False
    35.         End Try
    36.         Return True
    37.     End Function
    Last edited by stanav; Jan 25th, 2007 at 04:48 PM.

  14. #14

    Thread Starter
    New Member
    Join Date
    Jan 2007
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width