Arbitrary thoughts and musings on life, the universe and everything else
string to int[]
There's been a cool (I found it interesting) discussion on converting a comma-delimited string of int values into an int array lately. Gregory posted the details here.
The discussion carried forth to declare an inline method, instead of delegating to intToString, which seemed even more elegant: (the method was now only one line!)
int i[] = Array.ConvertAll<string, int>(commadelimitedInts.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries), new Converter<string, int>(delegate(string inVal) { return int.Parse(inVal); } ));There's in fact a better, more elegant way to do this than my inline method (thanks to colleague Piers!):
int i[] = Array.ConvertAll<string, int>(commadelimitedInts.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries), new Converter<string, int>(System.Convert.ToInt32));
Why not use the methods provided by the framework? :-)
Comments