How can I remove “\r\n” from a string in C#? Can I use a regular expression?

前端 未结 8 1651
粉色の甜心
粉色の甜心 2020-12-04 23:16

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 is left into a string array of 50 chara

相关标签:
8条回答
  • 2020-12-05 00:09

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

     myString = myString.Replace("\r\n", string.Empty);
    
    0 讨论(0)
  • 2020-12-05 00:10

    Nicer code for this:

    yourstring = yourstring.Replace(System.Environment.NewLine, string.Empty);
    
    0 讨论(0)
提交回复
热议问题