I am getting a string message through an event and I am putting it in a TextBox.
Unfortunatelly, this message has many empty lines. How do I replace two empty lines with one?
My first thought is for something like this:
string newLine = Environment.NewLine;
textbox.text = msg.Replace(newLine + newLine, newLine);
I am sure there is a better way to accomplish this.
But your
String.Replacesolution won’t work if there are three newlines in a row. For example, consider:s1will have multiple\ncharacters in it.s2will have only one.This is using
\nas an example, but the same thing applies if you’re usingEnvironment.NewLine(i.e.\r\n).