May 22
Here is one way to parse and sort a string with comma-delimited numbers:
string input = "1,9,3,4,3,9,1,5,6,78,"; string[] stringArray = input.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ); int length = stringArray.Length; int[] intArray = new int[length]; for (int i = 0; i < length; i++) { try { intArray[i] = Convert.ToInt32( stringArray[i] ); } catch (Exception) { // ignore } } Array.Sort( intArray );
Note how you must convert the numeric strings to integers BEFORE sorting. Otherwise you will end up with the sort order 6, 78, 9, for example. The Convert.ToInt32 method is enclosed in a try-catch block in case the numeric string does not contain a number, in which case it will default to 0.
Popularity: 35% [?]
Copyright © 2007-8 Tiwebb Ltd. All rights reserved. This material may not be published, broadcast, rewritten or redistributed without explicit permission from Tiwebb Ltd.


Uff I was way off.
Thanks