how to check if list of Items which are in alphanumeric shape are sorted asc and in desc order using c#

I have two lists of alphanumerics provided below, How could I ensure that they are sorted based on our regular expression i.e. [Z-A, 9-0] and [0-9, A-Z] . In list two blank should come first as mentioned in List-2.

List-1
T
S
IApplicationCache
D
A
10
9
8
7

Open in new window


List-2
""
1
2
34
56
A
B

Z

Open in new window

satmishaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kaufmed   ( ⚆ _ ⚆ )I asked the operating system what I could do to become a better programmer. It said, "Let me give you some pointers."Commented:
Your question is unclear. Are List1 and List2 both example of source data, or is one a "before" and the other an "after"?

Also, regular expressions are very literal constructs. Your pattern has a comma in it. In regex, a comma inside of braces would be evaluated as a potential character match. Is this what you intend, or is your pattern more pseudo-code?
Fernando SotoRetiredCommented:
Hi satmisha;

Adding to @kaufmed statements  this, " [Z-A, 9-0]", is also an invalid regex pattern seeming that the range is in reverse order. Also in sorting digit characters will not place them in numerical order. For example if you had the strings, "1", "4", "9", "12",  and it's  ascending sort order would result as , "1", "12", "4", "9".
satmishaAuthor Commented:
Apologies for non-clarity and thanks for replying. Answering your questions.

# Yes, Both List1 and List2 are examples of source data
# It is more of a scedo code indeed, [Z-A, 9-0] indicated reverse alphabetical order and [0-9, A-Z] indicates  in alphabetical order.
#  [Z-A, 9-0] is a scudo code indicating that it is in reverse alphabetic order.

I hope this answers your doubts.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

satmishaAuthor Commented:
apart from that during my research I stumbled upon one article i.e. https://www.dotnetperls.com/issorted which does make sence but it appears that it does not work well with alphanumeric string.
Fernando SotoRetiredCommented:
In the link to the article "The SortTools" you posted what do you mean, "but it appears that it does not work well with alphanumeric string", is that due to the issue I stated in my last post?
satmishaAuthor Commented:
Thank you, Fernando.

Providing below details, hope this will clear the question in more details...now..

I am using the Datatable jquery plugin to sort the table which sorts well but when I compared the output of the same input with the c# code I found it is different. I have no idea why is it so and which sort is right. Enclosing runable code for c# with output, and the output of the DataTable js plugin sort.

using System;
using System.Collections.Generic;
					
public class Program
{
	public static void Main()
	{
		List<string> colors = new List<string>
        {
           
"VW Transporter (AMB Equipement)",
"VW Transporter - OBD (AMB EQUIPEMENT)",
"Vauxhall Insignia - Unit 390622",
"Vauxhall Insignia (TCSV11 Rev G – battery mounted)"

        };
        // Call Array.Sort method.
        List<String> displayNamesSorted = new List<string>(colors);
                        displayNamesSorted.Sort();
                        displayNamesSorted.Reverse();
                        
		
		foreach (string color in displayNamesSorted)
        {
            Console.WriteLine(color);
        }
	}
}

Open in new window


Output:
VW Transporter (AMB Equipement)
VW Transporter - OBD (AMB EQUIPEMENT)
Vauxhall Insignia (TCSV11 Rev G – battery mounted)
Vauxhall Insignia - Unit 390622


whereas when I sort using DataTable.js plugin of Jquery it comes out:

VW Transporter - OBD (AMB EQUIPEMENT)
VW Transporter (AMB Equipement)
Vauxhall Insignia - Unit 390622
Vauxhall Insignia (TCSV11 Rev G – battery mounted)
Fernando SotoRetiredCommented:
Hi satmisha;

In C# sorting is accomplished by where the character falls with in the ASCII code table. For example the character 'A' has a numeric value of 65 and the character 'a' has a numeric value of 97. When sorting 'A' comes before 'a' and also why numeric characters don't sort naturally. In your example for the C# version the character '(' has a numeric value of 40 while the character '-' has a value of 45 and the reason why '(' comes before '-'. It is apparent that the Jquery sort order for the DataTable is not the same as what used in this C# version. This does not make one sort algorithm more correct than another. I have not worked with the Jquery DataTable plug-in but I believe it has a way to provide your own sorthing algorithm to override the supplied one.

I hope that helped in answering your question.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
satmishaAuthor Commented:
Thank you Fernando Soto. Appreciate your time :-).
Fernando SotoRetiredCommented:
Not a problem satmisha, glad to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.