Deleting line Breaks after text

Hello,I wish to find out how to delete line breaks at the end of a document. I have one variable that has accompainying space after it, on special case I wish this to be to be deleted.
I can delete a merge field no problem and now wish to delete all line breaks after this field only.
How do I do this?
If I could call a truncate function with this field would be appropriate? Is there a aspose function for this?
I found RemoveEmptyParagraphs but I do not want to do for the whole document only after a special merge Field name.
Thank you

Hi,
Please attach a sample document to take a look and specify the name of the merge field. Are the line breaks to delete real line breaks (inserted by pressing Shift-Enter in MS Word) or paragraph breaks?

Hi DmitryV,I need to delete paragraph breaks.Is there a standard functions for this in aspose?I can delete in line where processing progress is going from.Can also use moveToEndOf Document.
Thank you
Andrew

Hi Andrew,
Unfortunately, I can’t see anything attached that would allow me to test the issue. Here is a code example based on your description (on condition that the merge field retains in the document):

Document doc = new Document("D:\\TestField.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToMergeField("TestField");
Paragraph para = builder.CurrentParagraph;
while ((para == null) || (para.Runs.Count == 0))
{
    Paragraph nextPara = (Paragraph) para.NextSibling;
    para.Remove();
    para = nextPara;
}
doc.Save("D:\\TestField Out.doc");

Please attach your document if the solution does not work.

What does this mean here? Does it mean if the count is 0, its a line break?

@user1211 runs.count == 0 means there re no Run child nodes in the paragraph, i.e. no text. So in most cases the paragraph can be considered as empty. But there might be other child node types in the paragraph. For example shapes.

1 Like