- using System;
- using System.Text.RegularExpressions;
- public class Example
- {
- public static void Main()
- {
- try
- {
- string input = "This is text with far too much " + "whitespace.";
- string pattern = "\\s+";
- string replacement = " ";
- Regex rgx = new Regex(pattern);
- string result = rgx.Replace(input, replacement);
- Console.WriteLine("Original String: {0}", input);
- Console.WriteLine("Replacement String: {0}", result);
- Console.Read();
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
将多个空格换成一个空格(正则表达式)
最新推荐文章于 2023-12-20 10:02:27 发布