Delete last char of string
strgroupids = strgroupids.Remove(strgroupids.Length - 1);
MSDN:
String.Remove(Int32):
Deletes all the characters from this string beginning at a specified position and continuing through the last position
What about doing it this way
strgroupids = string.Join( ",", groupIds );
A lot cleaner.
It will append all elements inside groupIds
with a ','
between each, but it will not put a ','
at the end.