Re: Sorting help
- From: "Michael W. Ryder" <_mwryder@xxxxxxxxxxxxxxxx>
- Date: Mon, 13 Oct 2008 00:02:39 GMT
Ron Askew wrote:
I the values are actually numeric, they should be stored as numerics,
manipulated as numerics, and sorted as numerics.
So... the question is: WHY ARE THEY STRINGS?
The data may be coming from another source that the OP has no control over. In the language I do most of my programming in, Business Basic, everything is stored as a string, so 12.35 is stored as "12.25" instead of it's binary representation.
When I have this problem in Business Basic what I do is add leading zeros before storing the numbers in a file. The file system in Business Basic allows me to store records in a file and automatically sorts them by the key value. This means that you have to know in advance the size of the numbers.
What I would do is store the strings as ["10.1", "07.4", "10.9", "10.11", "10.10"] and this should sort properly. In the second case I would store the number as "10.01.25". Now if the numbers are something like TCP addresses this method probably won't work.
From: binh@xxxxxxxxxxx [mailto:binh@xxxxxxxxxxx] Sent: Sunday, October 12, 2008 7:24 PM
To: ruby-talk ML
Subject: Sorting help
I would like to request some helping with a sorting problem I have.
Given an array with values like this ["10.1", "7.4", "10.9", "10.11",
when I sort it i get something like ["10.1", "10.10", "10.11", "10.9",
What is the best way to sort such an array of strings?
What if the string was extended to "10.1.25".
Any advice would be greatly appreciated.
- Prev by Date: Re: Sorting help
- Next by Date: need help with code translation from VB
- Previous by thread: Re: Sorting help
- Next by thread: Re: Sorting help