# [Gambas-user] Ordering a bi-dimensional string[]...by several columns help wanted.

Jorge Carrión shordi at gmail.com
Sun Dec 2 21:23:51 CET 2018

```Got it!

Thanks everybody for the answers and the advices. After 5 days of thick
mind running, I've found a solution that is "perfect" for me.
It's only valid for strings and if your language has non-english characters
you must  adecuate the code to it but it works... And much faster than
other solutions I've tried.
The trick is a function that "reverses" the characters of the descendent
keys. So a = z, b=y,c=x, and so on.
Yes, I know is a little tricky, but it works.
Attached there is a example. It needs elaboration, but the idea is shown on
it.

El dom., 2 dic. 2018 a las 18:30, Charlie Ogier (<charlie at cogier.com>)
escribió:

> Hi Jorge,
>
> My solution: -
>
> Your data is "Country code", "Town" so: -
>
> *Data[0,0] = "US" *and* Data[1,0] = "New York"*
> *Data[0,1] = "UK"* and
> *Data[1,1] = "London" *
>
> *Etc *We want to sort by the "Town" (So we put it first)
>
> Create a *New String[]* with "Town" <separator> "Country Code"
> <separator> "Town"
>
> *SortList.Add(Data[1,0] & "`" & Data[0,0] & "`" Data[1,0])*
> *SortList.Add(Data[1,1] & "`" & Data[0,1] & "`" Data[1,1])*
> (use a loop)
>
> Sort the list
> *SortList.Sort()*
>
> Now rebuild *Data* with the 2nd and 3rd items
>
> *For iLoop = 0 to ?*
> *    Data[iLoop,0] = Split(SortList[iLoop],"`")[1]* ' "UK"
> *    Data[iLoop,1] = Split(SortList[iLoop],"`")[2] *' "London"
> *Next*
>
> See example attached.
>
> Charlie
>
>
> On 01/12/2018 18:13, Jorge Carrión wrote:
>
> The problem:
>
> I need order a bi-dimensional array by several columns following de user's
> criteria.
>
> It is relatively simple to order a two-dimensional array for a column, not
> long ago we saw several solutions in this mail list, but what I need now is
> to sort by several columns and that each of them can be ascending or
> descending.
>
> I confess that I have been stuck with the subject for four days, that I
> have believed more than once that I had solved it and that in the end I
> have given up doing it alone. Does anyone have any idea how to approach the
> issue before it drives me crazy?
>
> There is a "tricky" solution: grab your two-dimensional array, create with
> it a sqlite base and let the sqlite engine solve the issue with an SQL
> statement ... but this is not the case (it would force the project to link
> with the modules database and it's not always convenient)
>
> Waiting for the better minds than mine advice...
>
> Best Regards
>
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
>
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181202/75493bc4/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sortTable-0.0.1.tar.gz
Type: application/gzip
Size: 22984 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181202/75493bc4/attachment-0001.gz>
```