c# br br br to n use regex
To convert the line breaks in a C# string from <br>, <br />, and <br/> to \n using regex, you can use the following code:
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string input = "This is a <br>sample <br />text with<br/>line breaks.";
// Replace <br>, <br />, and <br/> with \n
string output = Regex.Replace(input, @"<br\s*/?>", "\n");
Console.WriteLine(output);
}
}
This code uses the Regex.Replace method to find occurrences of <br>, <br />, and <br/> in the input string and replaces them with \n. The resulting string is then printed to the console
AI 优化版
原文地址:https://www.cveoy.top/t/topic/hM0h 著作权归作者所有。请勿转载和采集!