Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting from Alphanumeric to nonAlphnumeric

Tags:

c#

sorting

I have a array of data:

!
A
B
E
$
N

I'd like it to be sorted from Alphanumeric to Non-Alphanumeric.

Example: A B E N ! $

How would I go about accomplishing this?

like image 681
Wesley Avatar asked Apr 07 '11 13:04

Wesley


1 Answers

char[] yourOriginalValues = new [] { '!', 'A', 'B', 'E', '$', 'N' };

IEnumerable<char> result = 
       yourOriginalValues.Where(c => Char.IsLetterOrDigit(c))
            .OrderBy(c => c)
            .Concat(yourOriginalValues.Where(c => !Char.IsLetterOrDigit(c)));

That seems to yield the values you're looking for.

like image 69
Adam Rackis Avatar answered Sep 29 '22 08:09

Adam Rackis