Forum:  Bugs & Issues

Thread:  Sort based On A Regular Expression or custom code

Dan1 (User)   Posted on: 02-Oct-2007 21:04:36.
Using v2.5.

I would like to use a regular expression to sort data returned from LLBLGen (either, returned datatable or projection).

In the past (before LLBLGen) I have had to return the recordset to a datatable. Manually add a column to the datatable in code and go through each row in a for/each and do the regular expression pattern match and append the matched values together into the new field. I would then take the dataset and pluck it into a dataview and sort on the added field. I was basically using the reg. exp. to do a pettern match and stripping characters out that didn't match that pattern and then sorting on the returned value.

This would be useful for those times where you need a specialized sort that cannot rely on either Ascending or Descending.

Here is an example of the code used to the the value to put in the new field and sort on:

        Dim x As New System.Text.RegularExpressions.Regex("\d+\.?\d*|\.\d+")
        'x = New System.Text.RegularExpressions.Regex("\b\d+\b")

        'Append each match to form one number
        Dim mc As Text.RegularExpressions.MatchCollection
        mc = x.Matches(st)
            If mc.Count > 1 Then
                Dim m As Text.RegularExpressions.Match
                Dim stReturn As String
                For Each m In mc
                    stReturn += m.ToString
                Return Val(stReturn)
                Return Val(x.Match(st).ToString)
            End If
        Catch ex As Exception
            'catch any errors - relating to Val or integer data type (maybe number was too long)
            Return Integer.MaxValue
        End Try

Walaa (Support Team)   Posted on: 03-Oct-2007 12:37:01.
You may try to use the EntityCollection.Sort() method, which accepts an IComparer.
So you can create your own comparer class implementing IComaprer and pass it to the Sort method.

Dan1 (User)   Posted on: 03-Oct-2007 15:17:35.

I'll look into that. I'll also look into using a BindingList of CustomClasses (that were projected to) and add a new property only used for sorting to the customclass and see if I can sort by that property in the bindinglist.