Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all commas from a string in C# 3

Tags:

c#-3.0

i have a string type variable like a="a,b,c,d";I want to remove all commas and get new value for a like abcd.I tried a.Replace(",","") but it is not working.I am using c# 3.0

like image 524
sajju217 Avatar asked Nov 19 '14 11:11

sajju217


2 Answers

Try this instead

a = a.Replace("," , "");

Edit

Your code is correct as far as using Replace() function goes. What you are missing is that Replace() does not modify the original string, it returns a new (updated) string which you should save.

like image 144
amyn Avatar answered Oct 24 '22 09:10

amyn


a.Replace(",", "");

Works for me, your problem lays else where. Also try this:

= String.Concat(a.Split(','));
like image 37
Nelson Pires Avatar answered Oct 24 '22 08:10

Nelson Pires