0

I have string like below.

string s="this is item1,item2,item3,,, ,, ,";

now i want to remove (,) from right side of string.

Thanks in advance

i have tried

string.Replace(",", "");

and

string.TrimEnd("'");

but not working

Gaurang s
  • 831
  • 6
  • 18

2 Answers2

4

Try this:

s = s.TrimEnd(',', ' ');

I think the problem in your code is that you do not assign the result of your replacement to any variable. And also your solution would remove all , from the string, not only those on the right side.

Flat Eric
  • 7,971
  • 9
  • 36
  • 45
3

Try string.TrimEnd():

s= s.TrimEnd(',',' ');
Kaf
  • 33,101
  • 7
  • 58
  • 78
Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61