Convert HTML Line Breaks (\u003cbr\u003e) to Newlines (\n) in C#
To convert the line breaks in a C# string from \u003cbr\u003e or \u003cbr /\u003e or \u003cbr/\u003e to \n, you can use the Replace method. Here's an example:
string input = "This is a test\u003cbr\u003estring.\u003cbr /\u003eIt contains multiple\u003cbr/\u003eline breaks.";
string output = input.Replace("\u003cbr\u003e", "\n").Replace("\u003cbr /\u003e", "\n").Replace("\u003cbr/\u003e", "\n");
Console.WriteLine(output);
Output:
This is a test
string.
It contains multiple
line breaks.
In the code above, we first replace all occurrences of \u003cbr\u003e with \n, then replace \u003cbr /\u003e with \n, and finally replace \u003cbr/\u003e with \n. This ensures that all variations of the line break tag are converted to the desired newline character.
原文地址: https://www.cveoy.top/t/topic/pv8h 著作权归作者所有。请勿转载和采集!