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 8758793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:38:22+00:00 2026-06-13T14:38:22+00:00

I have CSV data like this: Number;Version 1;AA.1 1;A01.1 1;A01.2 1;Z.7 Here, I need

  • 0

I have CSV data like this:

Number;Version
1;AA.1
1;A01.1
1;A01.2
1;Z.7

Here, I need to sort the Version column descending like following:

Number;Version
1;AA.1
1;Z.7
1;A01.2
1;A01.1

So if you see, the Z.7 entry should come after AA.1. basically the descending sorting should be done like:

Sorted Version:

BB
AA
Z
C
B
A

I’ve already tried the
Alphanum Algorithm discussed at http://www.DaveKoelle.com as well
Natural Sort Comparer at
http://www.codeproject.com/Articles/22517/Natural-Sort-Comparer. It does everything what I want except the sorting mentioned above.

  • 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-06-13T14:38:24+00:00Added an answer on June 13, 2026 at 2:38 pm

    So, this looks like you need to sort on some custom logic as followed in the CSV file. To perform this you must implement IComparer<string> on a class and implement the Compare method based on your requirement. Looks like in your case, you need to first split the string into two parts, the alphabets part and numeric part (using regular expression), then compare the string first, if both are same then compare number part and return the value accordingly.

    You can then use this Comparer class to sort them.

    Update

    Code sample

    public class CustomStringComparer : IComparer<string>
    {
        public int Compare(string x, string y)
        {
            int? result;
            if (AnyParamIsNull(x, y, out result))
            {
                return result.Value;
            }
    
            string x1, y1;
            double x2, y2;
            SplitInput(x, out x1, out x2);
            SplitInput(y, out y1, out y2);
            if (x1.Length == y1.Length)
            {
                result = string.Compare(x1, y1);
                if (result.Value == 0)
                {
    
                    if (x2 < y2)
                    {
                        return -1;
                    }
                    else if (x2 > y2)
                    {
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
    
    
                }
                else
                {
                    return result.Value;
                }
            }
            else
            {
                //To make AA before Z when desending
                return x1.Length - y1.Length;
            }
    
        }
    
        private bool SplitInput(string input, out string alphabets, out double number)
        {
            Regex regex = new Regex(@"\d*[.]?\d+");
            Match match = regex.Match(input);
            if (match.Success)
            {
                number = double.Parse(match.Value, CultureInfo.InvariantCulture);
                alphabets = input.Replace(match.Value, "");
                return true;
            }
            else
            {
                throw new ArgumentException("Input string is not of correct format", input);
            }
        }
    
    
        private bool AnyParamIsNull(string x, string y, out int? result)
        {
            result = null;
            if (x == null)
            {
                if (y == null)
                {
                    // If x is null and y is null, they're 
                    // equal.  
                    result = 0;
                    return true;
                }
                else
                {
                    // If x is null and y is not null, y 
                    // is greater.  
                    result = -1;
                    return true;
                }
            }
            else
            {
                // If x is not null... 
                // 
                if (y == null)
                // ...and y is null, x is greater.
                {
                    result = 1;
                    return true;
                }
            }
            return false;
        }
    }
    

    To use this Comparer

            List<string> input = new List<string>()
            {
                "AA.1",
                "A01.1",
                "A01.2",
                "Z.7"
            };
    
            input.Sort(new CustomStringComparer());
            //To sort decending
            input.Reverse();
    

    Caution: I have proved the above code is only correct and not otherwise. There can be some edge cases where it may not be working as expected

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

Sidebar

Related Questions

I have a csv file with data looking like (see below). I need help
I have CSV data of a log for 24 hours that looks like this:
I have a number of images and a CSV data file that I want
I have a .csv file containing 3 columns of data. I need to create
I have a Excel CSV files with employee records in them. Something like this:
We have written a number of SSIS packages that import data from CSV files
I have a need to import a number of CSV files into corresponding tables
Right now, if you have a test that looks like this: [TestMethod] [DeploymentItem(DataSource.csv)] [DataSource(
I have a bunch of data in a text file like this: 99150, 2012-05-18
I have a time series(a csv file) data that looks like below. Each observation

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.