如何删除" \\ r \\ n"在C#中的字符串?我可以使用正则表达式? [英] How can I remove "\r\n" from a string in c#? Can I use a regEx?

查看:176
本文介绍了如何删除" \\ r \\ n"在C#中的字符串?我可以使用正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从ASP.NET textarea的持续字符串。我需要去掉回车换行符,然后分手不管剩下成50个字符的字符串数组。

I am trying to persist string from an ASP.NET textarea. I need to strip out the carriage return line feeds and then break up whatever's left into a string array of 50 character pieces.

我有这到目前为止

var commentTxt = new string[] { };
var cmtTb = GridView1.Rows[rowIndex].FindControl("txtComments") as TextBox;
if (cmtTb != null)
  commentTxt = cmtTb.Text.Length > 50
      ? new[] {cmtTb.Text.Substring(0, 50), cmtTb.Text.Substring(51)}
      : new[] {cmtTb.Text};

它的工作好,但我不剥出CRLF字符。我该怎么做这正确?

It works ok, but I am not stripping out the CrLf characters. How do I do this correctly?

谢谢,
〜CK在圣地亚哥

Thanks, ~ck in San Diego

推荐答案

您可以使用正则表达式,是的,但一个简单的与string.replace()可能就足够了。

You could use a regex, yes, but a simple string.Replace() will probably suffice.

 myString = myString.Replace("\r\n", string.Empty);

这篇关于如何删除" \\ r \\ n"在C#中的字符串?我可以使用正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆