Mixed numeric/alphabetic sort ("Foo 9" should be before "Foo 10") in AS

View: New views
2 Messages — Rating Filter:   Alert me  

Mixed numeric/alphabetic sort ("Foo 9" should be before "Foo 10") in AS

by adamcath123 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I want to sort some strings. My strings have letters and numbers. An alphabetic sort would be wrong - it would put "Foo 10" before "Foo 9". I want the kind of sorting that a modern OS does on filenames: alphabetic on the letters and numeric on the numbers.

How do you do this in AS?

Does this problem have a standard name? I've had bad results trying to search for it...


Re: Mixed numeric/alphabetic sort ("Foo 9" should be before "Foo 10") in AS

by valdhor-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

AFAIK this is called natural sorting or lexicographical sorting.

Here are a few resources that should help you on your way...

http://www.davekoelle.com/alphanum.html
http://www.pranaframework.org/docs/0.7/api/org/springextensions/actionscript/utils/StringUtils.html#naturalCompare%28%29
http://code.google.com/p/as3natcompare/

HTH



Steve


--- In flexcoders@..., "adamcath123" <adam_cath@...> wrote:
>
> I want to sort some strings. My strings have letters and numbers. An alphabetic sort would be wrong - it would put "Foo 10" before "Foo 9". I want the kind of sorting that a modern OS does on filenames: alphabetic on the letters and numeric on the numbers.
>
> How do you do this in AS?
>
> Does this problem have a standard name? I've had bad results trying to search for it...
>