使用C#处理字符串是一个常见的情况,当字符串中含有空格或者换行符号的时候,如果业务需要,我们可以通过相应的方法将之处理掉,处理成不含空格和换行符号的字符串,处理的过程使用到正则表达式。

具体函数处理的过程如下:

static void Main(string[] args)
        {
            List<string> list = new List<string>();
            list.Add("\r \n aab bcc");
            list.Add("aab bcc \r  \ndd");
            list.Add("aa\r b b \n cc");
            
            Regex regex = new Regex(@"\s");
            for (int i = 0; i < list.Count;i++ )
            {
                string str = list[i];
                list[i]=regex.Replace(str,"",str.Length);
            }

            foreach(string s in list)
            {
                Console.WriteLine(s);
            }
        }

 

扩展阅读:目前国内主流的云服务器厂商有哪些_IT技术小趣屋

备注:原文转载自C#处理空格和换行_IT技术小趣屋

相关文章:

  • 2022-12-23
  • 2021-10-08
  • 2021-08-28
  • 2021-08-14
  • 2021-07-29
  • 2021-12-25
  • 2022-12-23
猜你喜欢
  • 2021-11-24
  • 2021-11-16
  • 2021-11-16
  • 2021-10-18
  • 2021-12-28
  • 2022-02-09
相关资源
相似解决方案