开发工具 Visual Studio 2010
using System;
using System.Text.RegularExpressions;
namespace RegularExpressionsTest
{
class Program
{
static void Main(string[] args)
{
string pattern = @"[,\s]+";
string replacement = ",";
string input = "test1,test2 test3 test4,,test5, test6 ,test7 test8,,,test9,, ,test10";
string result = Regex.Replace(input, pattern, replacement);
Console.WriteLine(result);
Console.ReadLine();
}
}
}
运行输出