LEM,
I think that there is an easier way to do this:
string pp = "\r\n\r\n1\r\n23\r\n\r\n4";
// Cycle through the string and remove all empty lines.
string line = null;
// The result. You pass the length of the string for the capacity, because
you might not remove anything.
// Additionally, you add the length of the line terminator because if the
original string didn't have a
// new line character sequence at the end, you will be adding one at the end
of the following loop,
// so you need to know the length of those characters.
StringBuilder result = new StringBuilder(pp.Length +
Environment.NewLine.Length);
// Use a StringReader.
using (StringReader reader = new StringReader(pp))
{
// Cycle through while there are lines to read.
while ((line = reader.ReadLine()) != null)
{
// Add the line with a newline.
result.AppendLine(line);
}
}
Now you have the result in the StringBuilder.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
using (
"LEM" <an*******@nospam.comwrote in message
news:OS**************@TK2MSFTNGP04.phx.gbl...
Hi,
I'm trying to remove any empty lines from a string, and I am doing the
following:
String pp;
pp = "\r\n\r\n1\r\n23\r\n\r\n4";
pp = pp.Replace("\r\n\r\n", "\r\n");
That works fine if the first line of the string is NOT empty.
How could I remove the first line as well?
Thanks