[SOLVED] 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(new char[] { ',' });

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


strgroupids = strgroupids.Remove(strgroupids.Length - 1);



Deletes all the characters from this string beginning at a specified
position and continuing through the last position

Answered By – sll

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *