A Function to Concat String Array Values by Specified Delimiter

2:13 AM
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,",");

0 comments:

Post a Comment