Skip to main content
A newer version of this page is available. .

How to: Remove Blank Lines from a Document

This code example shows how to delete excessive blank lines from a document.

Call the SubDocument.ReplaceAll method with the corresponding regular expression as the search parameter. Then save the result.


Document document = richEditDocumentServer1.Document;
document.LoadDocument("Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
string pattern = @"((?<=^)|(?<=\n))\n";
string replacementString = string.Empty;
System.Text.RegularExpressions.Regex myRegEx = new System.Text.RegularExpressions.Regex(pattern);
int count = document.ReplaceAll(myRegEx, replacementString);
System.Windows.Forms.MessageBox.Show(String.Format("{0} blank lines have been removed",count));