Ideas for sorting strings containing characters and numerics

alsnchns

New member
Joined
Sep 11, 2006
Messages
2
Programming Experience
Beginner
I have an array of strings. The strings are a combo of numerics and alphas.

Example strings:
ASM100 ASM112 R1000 R1009 R1018 R1027 R237 R247 R250 R500 R501 R600 R801 R803 R820 R821 R822 R823 R900 R901 R902 R903 R909 R910 R911 R912

Using a simple bubble sort yields the results shown above. What I need is for the sort to exclude the characters and sort using only the numeric portion. That is, R1000, R1009, R1018, R1027 should be at the end of the sort instead of the beginning. Is there a simple method for obtaining this type of sort without stripping the alpha portion from string, converting to integer, then adding the character portion back? Thanks
 
Not that I'm aware of. Having said that, you don't have to create a new array and fill it with numeric parts and sort that. You just have to write your own IComparer class that will do it for two objects being compared. You then pass an instance of that class to the appropriate overload of Array.Sort and it will sort the existing array. Go to MSDN and look up the tpic for the Array.Sort method, then read about the overload(s) that take an IComparer object as a parameter.
 
Back
Top