Regex that matches a newline (\n) in C#

前端 未结 6 1967
你的背包
你的背包 2020-11-30 07:08

OK, this one is driving me nuts.... I have a string that is formed thus:

var newContent = string.Format(\"({0})\\n{1}\", stripped_content, reply)
         


        
6条回答
  •  春和景丽
    2020-11-30 08:04

    If you specify RegexOptions.Multiline then you can use ^ and $ to match the start and end of a line, respectively.

    If you don't wish to use this option, remember that a new line may be any one of the following: \n, \r, \r\n, so instead of looking only for \n, you should perhaps use something like: [\n\r]+, or more exactly: (\n|\r|\r\n).

提交回复
热议问题