Remove all the empty rows in the table after the last row which has data in aspose c#

Hi,
how to remove all the empty rows in the table after the last row which has data in a table using Aspose c#. And should not delete the rows which are empty between 1st to last row. If this can be done with benchmark of the table that could be good because I have lots of table in a word. If you could share a sample would be great.

Help will be appreciated!

@kiran5388 You can use code like the following to remove empty table rows at the end of table:

Document doc = new Document(@"C:\Temp\in.docx");

// Get table. For demonstration purposes the first table is used.
Table table = doc.FirstSection.Body.Tables[0];

// Remove all empty rows at the end of the table.
while (string.IsNullOrEmpty(table.LastRow.ToString(SaveFormat.Text).Trim()))
    table.LastRow.Remove();

doc.Save(@"C:\Temp\out.docx");

thanks for the reply.
In the while loop you are just finding the last row of the table which is empty and you are removing that. But more empty rows above that will be remained

May be finding the last row with data in a table could help removing the rest of the blank rows

@kiran5388 The code removes all empty rows at the end of table that appears before the last row with data.
Could you please attach your input and expected output documents here for testing?

Thanks, I got you.
Sorry, Actually I am having a table row in which there are ‘\r’. I am trying to get rid of those.

@kiran5388 Could you please attach your input document and expected output here? We will check your documents and provide you more information.