Sunday, May 19, 2013

Convert a comma separated string into ArrayList in ASP.net

Using below code we can easily Convert a comma separated string or any other string having any type of separator into ArrayList in ASP.net

ArrayList ConvertStringToArray(string pagesNameList)
        {
            ArrayList List=null;
            if (!(pagesNameList == null))
            {
                string[] pagesName = pagesNameList.Split('~');

                List = new ArrayList(pagesName.Length);
                int index=0;
               for (index=0;index<=pagesName.Length-1; index ++)
                {
                    List.Add(pagesName[index]);
                }
            }
            return List;
        }