sajju217
sajju217

Reputation: 467

Remove all commas from a string in C# 3

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

Upvotes: 17

Views: 68708

Answers (2)

amyn
amyn

Reputation: 942

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.

Upvotes: 55

Nelson Pires
Nelson Pires

Reputation: 321

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

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

= String.Concat(a.Split(','));

Upvotes: 3

Related Questions