How to split a 2-D array?

SONYFX

Senior member
May 14, 2003
403
0
0

For example when do a database query I have 3 columns and 4 rows returned as String[][] :


ID, CITY, COUNTRY
------------------------
1, NY, USA
2, NY, USA
3, NY, USA
4, HK, CHINA


How do I split the returned array into two separate String[][] based on COUNTRY? i.e. one array for USA and one array for CHINA. (I don't want to do two database queries)
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
china = string[]
us = string[]
for city in cities:
__if (city[2] = 'USA') us.add(city)
__else china.add(city)

If you want to handle an arbitrary number of countries, instead of two arrays, use one dictionary of arrays. Alternatively, if you don't need individual city info (like you were only going for averages or something like that) you could look into a 'group by' query.
 

SONYFX

Senior member
May 14, 2003
403
0
0
Originally posted by: kamper
china = string[]
us = string[]
for city in cities:
__if (city[2] = 'USA') us.add(city)
__else china.add(city)

If you want to handle an arbitrary number of countries, instead of two arrays, use one dictionary of arrays. Alternatively, if you don't need individual city info (like you were only going for averages or something like that) you could look into a 'group by' query.

Thanks but I need to store the "whole row" in 2-D array.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
That's what my code does although my typing wasn't particularly clear (it's just pseudo-code after all). 'china' and 'us' should be string[][].