当前位置: 移动技术网 > IT编程>开发语言>.net > 【转载】C#处理空格和换行

【转载】C#处理空格和换行

2019年04月01日  | 移动技术网IT编程  | 我要评论

使用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);
            }
        }

 

备注:原文转载自。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网