-1

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

We will Call it Like This:
string str = GetAllStringsFromArrary( st,",");

Check here for better understanding: [snipped]

Edited by Ezzaral: Snipped link.

Votes + Comments
use string.Join!!
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;
             
 
        }
4
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by maximocn
0

Being a Posting Whiz, Have you never come across string.split and string.join inbuilt methods??..

Edited by samueal: n/a

1

my first comment was a little sarcasm .. yes i know about string.split and string.join very well..

this was snippet was made very long ago.. i just posted it here to share ...

and the title Posting Wiz doesn't mean i know it all.. even the most talented people have flaws.. :)

Votes + Comments
polite enough.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.