commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adrian Perez Jorge <ape...@ignos.com>
Subject Re: Sorting string array numerically
Date Fri, 30 Apr 2004 16:23:23 GMT
matthew.hawthorne wrote:

> Søren Blidorf wrote:
>
>> I have a problem regarding sorting numerically.
>>
>> I have the following pics:
>>
>> pic_1, pic_2, pic_3, pic_4, pic_5, pic_6, pic_7, pic_8, pic_9, 
>> pic_10, pic_11, pic_12
>>
>> But the sort makes a sort after first number then second number:
>>
>> pic_1, pic_10, pic_11, pic_12, pic_2, pic_3, pic_4, pic_5, pic_6, 
>> pic_7, pic_8, pic_9
>>
>> How can I make sure that the sort is numeric?
>>
>> pic_1, pic_2, pic_3, pic_4, pic_5, pic_6, pic_7, pic_8, pic_9, 
>> pic_10, pic_11, pic_12 
>
>
>
> I'm not sure if this is the right list for this type of message...

Nor me.

>
> But, you could write a custom Comparator, which parses the number from 
> the string.[...]


  Before implementing the comparator, I encourage to check out the 
function numcompare() from the GNU sort util at coreutils package.  You 
can get that code in the following URL:

    http://savannah.gnu.org/cgi-bin/viewcvs/coreutils/coreutils/src/sort.c

  Maybe a similar algorithm could be implemented in a future 
commons-string package ;)

Cheers,

Adrian P.J.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message