Share Blog

Saturday, July 28, 2018

Remove comma and add comma in string in c#


//remove comman and add comma
string department = "Support, Integration, Developer";
string dptment = "";
string[] dpt = department.Split(',');
for (int i = 0; i <= dpt.Length - 1; i++)
{
if (i == dpt.Length - 1)
{
dptment = dptment + dpt[i];
}
else
{
dptment = dptment + dpt[i] + ", ";
}
}
Console.WriteLine(dptment);
//remove comma and add without comman in list
List<string> lsttype = new List<string>();
string[] extracttype = department.Split(',');
for (int i = 0; i <= extracttype.Length - 1; i++)
{
lsttype.Add(extracttype[i]);
}
Console.WriteLine(lsttype.ToList());

No comments:

Post a Comment