To convert the line breaks in a C# string from "
", "
", and "
&quot; to &quot;\n&quot; using regex, you can use the following code: \n\ncsharp\nusing System;\nusing System.Text.RegularExpressions;\n\nclass Program\n{\n static void Main()\n {\n string input = \&quot;This is a <br>sample <br />text with<br/>line breaks.\&quot;;\n \n // Replace <br>, <br />, and <br/> with \n\n string output = Regex.Replace(input, \&quot;<br\s*/?>\&quot;, \&quot;\n\&quot;);\n \n Console.WriteLine(output);\n }\n}\n\n\nThis code uses the Regex.Replace method to find occurrences of &quot;
&quot;, &quot;
&quot;, and &quot;
&quot; in the input string and replaces them with &quot;\n&quot;. The resulting string is then printed to the console.

C# Regex: Replace <br> with \n -  Line Break Conversion

原文地址: https://www.cveoy.top/t/topic/pv8j 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录