Sunday, March 31, 2013

Convert a Comma Delimited String to an ArrayList in C#


In the previous post i had shown u how to Convert comma delimited string to Dictionary
Now i will show how to Convert comma delimited string to string array, is easy as shown below...



string Val = "a,b,c,d,e";

string[] myStringArray = Val.Split(',');


in the  same way converting comma delimited string to arraylist is also easy in a single line as shown below....

//Method1
ArrayList myArrayList = new ArrayList();
myArrayList.AddRange(Val.Split(','));



//Method 2
ArrayList list = new ArrayList(Val.Split(','));
 
 
Out Put :


myArrayList[0] = a;
myArrayList[1] = b;
myArrayList[2] = c; 
myArrayList[3] = d;
myArrayList[4] = e;

No comments:

Post a Comment