Tuesday, April 1, 2014

Removing double/ multiple comma from a string in c#

Use namespace:
using System.Text.RegularExpressions;

then do the following code:

string inputString = "'\"1\":\"C\",\"2\":\"A\",\"3\":\"C\",,\"5\":\"C\",\"6\":\"B\",,\"8\":\"C\",,\"10\":\"C\",'";
string outputString = Regex.Replace(inputString, ",{2,}", ",").Trim(',');

No comments:

Post a Comment