Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created March 6, 2018 15:00
Show Gist options
  • Save bjoerntx/91cea7efc1d2280bb8b0203ab4bda8f3 to your computer and use it in GitHub Desktop.
Save bjoerntx/91cea7efc1d2280bb8b0203ab4bda8f3 to your computer and use it in GitHub Desktop.
private bool RemoveEmptyFieldLines()
{
foreach (IFormattedText obj in serverTextControl1.TextParts)
{
foreach (ApplicationField field in obj.ApplicationFields)
{
// check, if character next to empty field is a carriage return
if (obj.TextChars[field.Start + field.Length].Char == '\n')
{
bool bCompleteLine =
(field.Start == obj.Lines.GetItem(field.Start).Start)
? true : false;
// if yes, remove the field
obj.Selection.Start = field.Start;
obj.ApplicationFields.Remove(field, false);
// if the field is the only text in the line
// remove the CR
if (bCompleteLine)
{
obj.Selection.Length = 1;
obj.Selection.Text = "";
}
// call RemoveEmptyFieldLines recursively
return true;
}
else
field.Text = "";
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment