Regex.Replace()

作者:追风剑情 发布于:2014-8-6 16:30 分类:C#

开发工具 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();
        }
    }
}

运行输出

输出结果.png

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号