Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:08:57+00:00 2026-05-29T11:08:57+00:00

I have an app which is displaying a data set which allows me to

  • 0

I have an app which is displaying a data set which allows me to call out to custom .NET code and am stuck on a sorting problem. One column in my data set contains both strings and numeric data, and I want to sort the strings alphabetically and the numbers numerically. All I can do is take the current value the sorter is working with, and return something.

If my list is {“-6”, “10”, “5”}, I want to produce strings from those numbers that would sort them alphabetically. What I’ve come up with is making them all positive, then padding with zeros, like this:

public object Evaluate(object currentValue)
{
    //add 'a' to beginning of non-numbers, 'b' to beginning of numbers so that numbers come second
    string sortOrder = "";
    if(!currentValue.IsNumber)
        sortOrder = "a" + currentValue;
    else
    {
        sortOrder = "b"
        double number = Double.Parse(currentValue);

        //add Double.MaxValue to our number so that we 'hopefully' get rid of negative numbers, but don't go past Double.MaxValue
        number += (Double.MaxValue / 2)

        //pad with zeros so that 5 comes before 10 alphabetically:
        //"0000000005"
        //"0000000010"
        string paddedNumberString = padWithZeros(number.ToString())


        //"b0000000005"
        //"b0000000010"
        sortOrder += paddedNumberString;
    }
}

Problem:
If I simply return the number, then they get sorted alphabetically and 10 will come before 5, and I don’t even know what will happen with negative numbers.

Solution?:
One hack I thought of was trying to convert from doubles (8 bytes) to unsigned longs (8 bytes). That would get rid of negative numbers since they would be starting at 0. The problem of 10 coming before 5 still remains though. For that, perhaps pad with 0s or something…

It seems like this should be possible, but I have the dumb today and can’t smart.

example data:
‘cat’
‘4’
‘5.4’
‘dog’
‘-400’
‘aardvark’
‘12.23.34.54’
‘i am a sentence’
‘0’

that should be sorted to:
‘12.23.34.54’
‘aardvark’
‘cat’
‘dog’
‘i am a sentence’
‘-400’
‘0’
‘4’
‘5.4’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:08:57+00:00Added an answer on May 29, 2026 at 11:08 am

    I suspect you’re after something called ‘Natural Sort order’.
    Attwood has a post on it: http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html

    There’s a couple examples of implementations in the post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an App which launches the google Map App. The code is: UIApplication
I have an iPhone app which, when it launches, loads in data from a
In my WPF app I have a data import function which imports data from
Im working on an ASP.Net app with c#. I am stuck on a problem
I have a WPF App which is grinding to a halt after running out
i have a long list selector in which i'm displaying data sorted by date.
I have an iPhone app which communicates with a server to get the data
I have an app which could benefit from the user being able to choose
I have an app which consists of several different assemblies, one of which holds
I have wxPython app which is running on MS Windows and I'd like it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.