Convert string array of numbers to int array
Posted on: Thu Sep 11 15:34:43 -0700 2008. Updated on: Thu Sep 11 15:57:49 -0700 2008.
Category: DotNet
Category: DotNet
Lets say you have a comma delimited list of id's in a string object. You want to get these id's into a int[] array. Here is how to do it quick:
string[] idList = someIDs.Split(',');
int[] intIdList = Array.ConvertAll(idList, new Converter<string, int>(StringToInt32));
You will also need to define the follow static function
public static int StringToInt32(string number)
{
return Convert.ToInt32(number);
}
Wasn't that easy? Note that you can convert other object types too, not simply string to int.
Fri Sep 12 11:12:33 -0700 2008
That is clever... Know I coud use this here and there
---------------------------------------------------