I have several blank line in my richbox and I need to remove them from rich.
I can fine blank lines but can't remove them. how can I do it? I used this code but it didn't work:
RichTextBox rtfBox = new RichTextBox();
rtfBox.Rtf = SOME NTEXT DATA;
int lineNumber = 0;
foreach (string a in rtfBox.Lines)
{
if (a == "")
{
int start_index = rtfBox.GetFirstCharIndexFromLine(lineNumber);
int countLineChar = rtfBox.Lines[lineNumber].Length;
// Eat new line chars
if (lineNumber < rtfBox.Lines.Length - 1)
{
countLineChar += rtfBox.GetFirstCharIndexFromLine(lineNumber + 1) -
((start_index + countLineChar - 1) + 1);
}
rtfBox.Text = rtfBox.Text.Remove(start_index, countLineChar);
}
else
lineNumber++;
}
this line rtfBox.Text = rtfBox.Text.Remove(start_index, countLineChar);
don't work.
thanks
Update
Thanks everybody, your suggestion are useful when richbox content is just text, but I have image and table in my rich too. when I use rtb.Text = or rtfBox.Text = or richTextBox1.Text = images and tables will be remove from richbox.