Jump to content
Tommi Prami

"natural" compare function for sort

Recommended Posts

Hello is there any implementation for compare function for ordering strings with numbers into numeric order:

Random list to this:

1 test

2 test

10 test

11 test

20 test

21 test
test 1

test 2

test 10

test 11

test 12

test 20

 

etc,

Edited by Tommi Prami

Share this post


Link to post
2 minutes ago, FPiette said:

Are you showing the list sorted as you like or is it the unsorted list?

Sorry bad example. Edited the list a bit.

Not just alphabetically but numbers would always be Smaller or larger first (depending if Ascending or Descending sort).

 

Can't remeber which this was called. Maybe natural sort etc.,.,

Share this post


Link to post

If you like my answer, you should like it (The heart icon on the answer bottom right). Thanks.

 

  • Like 1

Share this post


Link to post

TStringHelper.Compare has an overload where you can give the option TCompareOption.coDigitAsNumbers for this purpose.

  • Like 3
  • Thanks 1

Share this post


Link to post
3 hours ago, FPiette said:

If you like my answer, you should like it (The heart icon on the answer bottom right). Thanks.

 

Seems a bit needy

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×