Created
June 3, 2024 12:53
-
-
Save bjoerntx/3cf42f086e9b9f21327790df92f6269b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<string> ExtractTextBlocks(string paragraphStyleName, ServerTextControl serverTextControl, bool includeRemainingText) | |
{ | |
List<string> textBlocks = new List<string>(); | |
bool capturing = false; | |
StringBuilder currentBlock = new StringBuilder(); | |
for (int i = 1; i < serverTextControl.Paragraphs.Count - 1; i++) | |
{ | |
Paragraph paragraph = serverTextControl.Paragraphs[i]; | |
if (paragraph.FormattingStyle == paragraphStyleName) | |
{ | |
if (capturing) | |
{ | |
textBlocks.Add(currentBlock.ToString().Trim()); | |
currentBlock.Clear(); | |
} | |
else | |
{ | |
capturing = true; | |
} | |
} | |
else if (capturing) | |
{ | |
currentBlock.AppendLine(paragraph.Text); | |
} | |
} | |
// Add remaining text if still capturing at the end | |
if (includeRemainingText && (capturing || currentBlock.Length > 0)) | |
{ | |
textBlocks.Add(currentBlock.ToString().Trim()); | |
} | |
return textBlocks; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment