C# Regex: Replace <br> with \n - Line Break Conversion
To convert the line breaks in a C# string from "
", "
", and "
" to "\n" 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 = \"This is a <br>sample <br />text with<br/>line breaks.\";\n \n // Replace <br>, <br />, and <br/> with \n\n string output = Regex.Replace(input, \"<br\s*/?>\", \"\n\");\n \n Console.WriteLine(output);\n }\n}\n\n\nThis code uses the Regex.Replace method to find occurrences of "
", "
", and "
" in the input string and replaces them with "\n". The resulting string is then printed to the console.
原文地址: https://www.cveoy.top/t/topic/pv8j 著作权归作者所有。请勿转载和采集!