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

Charlie Ogier charlie at cogier.com
Sun Dec 2 18:04:11 CET 2018

```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 ]----

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181202/3709a13c/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NewTest.tar.gz
Type: application/gzip
Size: 14645 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181202/3709a13c/attachment-0001.gz>
```