Delete last char of string

I am retrieving a lot of information in a list, linked to a database and I want to create a string of groups, for someone who is connected to the website.

I use this to test but this is not dynamic, so it is really bad:

string strgroupids = "6";

I want to use this now. But the string returned is something like 1,2,3,4,5,

groupIds.ForEach((g) =>
{
    strgroupids = strgroupids  + g.ToString() + ",";
    strgroupids.TrimEnd(',');
});

strgroupids.TrimEnd(new char[] { ',' });

I want to delete the , after the 5 but it’s definitely not working.

12 Answers
12

Leave a Comment