A Function To Concat String Array Values By Specified Delimiter

Let 's Say I have Following Array:

string[] st = new string[5];
            st[0] = "Animation";
            st[1] = "Action";
            st[2] = "Romance";
            st[3] = "Drame";
            st[4] = "Comedy";


Now I want to Merge all of it with ',' Delimiter Like Below:

Output :   Animation,Action,Romance,Drame,Comedy


Here is the Function For the Above

public string GetAllStringsFromArrary(string[] strArray,string strDelimeter)
        {
            string strFinal = string.Empty;

            for (int i = 0; i < strArray.Length ; i++)
            {
                strFinal += strArray[i];

                if (i != strArray.Length - 1)
                {
                    strFinal += strDelimeter;
                }
            }
            return strFinal;
            

        }

We will Call it Like This:

string str = GetAllStringsFromArrary( st,",");
posted @ 2012-04-01 19:56  sandeepparekh9  阅读(176)  评论(0)    收藏  举报