Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Remove Blank Lines from a Document

To delete excessive blank lines from a loaded document, execute the SubDocument.ReplaceAll with the appropriate regular expression as the search parameter. Then save the resulting document.

The following code snippet removes repetitive blank lines.

View Example

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));