通过正则表达式 Regex.Replace() 和匹配符 \s(匹配任何空白字符,包括空格、制表符、换页符等,与[\f\n\t\r\v]等效),代码如下:
using System;
using System.Text.RegularExpressions;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            string testStr = "  this\n is\r a \ttest   ";
            Console.WriteLine(Regex.Replace(testStr, @"\s", ""));

            Console.Read();
        }
    }
}

运行结果如下:

C# 字符串 string 去除所有空格

 

 

    

 

 

相关文章:

  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-04
  • 2022-12-23
  • 2022-02-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
相关资源
相似解决方案