Skip to content

Commit 188c651

Browse files
committed
Changed the variable name.
1 parent 00528e8 commit 188c651

File tree

1 file changed

+6
-6
lines changed
  • Find-item-in-word-document/Delete-Bracketed-Content-Up-To-Specific-Word/.NET/Delete-Bracketed-Content-Up-To-Specific-Word

1 file changed

+6
-6
lines changed

Find-item-in-word-document/Delete-Bracketed-Content-Up-To-Specific-Word/.NET/Delete-Bracketed-Content-Up-To-Specific-Word/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public static void Main(string[] args)
2121
// Find the position (index) of the paragraph in the section
2222
int phraseParaIndex = ownerSection.Body.ChildEntities.IndexOf(paragraph);
2323
// Find the position of the word inside the paragraph
24-
int phraseEntityIndex = paragraph.ChildEntities.IndexOf(selection.GetAsOneRange());
24+
int matchWordIndex = paragraph.ChildEntities.IndexOf(selection.GetAsOneRange());
2525
// Set how many paragraphs before the word we want to check
2626
int maxPreviousParagraphs = 6;
2727
// Call a method to remove content inside brackets before the word
28-
RemoveBlock(document, paragraph, phraseParaIndex, phraseEntityIndex, ownerSection, maxPreviousParagraphs);
28+
RemoveBlock(document, paragraph, phraseParaIndex, matchWordIndex, ownerSection, maxPreviousParagraphs);
2929
// Save the updated document to a file
3030
document.Save(@"../../../Output/Output.docx");
3131
}
@@ -37,10 +37,10 @@ public static void Main(string[] args)
3737
/// <param name="document">The Word document to modify.</param>
3838
/// <param name="paragraph">The paragraph that contains the specific word or phrase.</param>
3939
/// <param name="phraseParaIndex">The index of the paragraph containing the specific word.</param>
40-
/// <param name="phraseEntityIndex">The index of the word within the paragraph.</param>
40+
/// <param name="matchWordIndex">The index of the word within the paragraph.</param>
4141
/// <param name="ownerSection">The section that contains the paragraph.</param>
4242
/// <param name="maxPreviousParagraphs">The number of previous paragraphs to check for bracketed content.</param>
43-
private static void RemoveBlock(WordDocument document, WParagraph paragraph, int phraseParaIndex, int phraseEntityIndex, WSection ownerSection, int maxPreviousParagraphs)
43+
private static void RemoveBlock(WordDocument document, WParagraph paragraph, int phraseParaIndex, int matchWordIndex, WSection ownerSection, int maxPreviousParagraphs)
4444
{
4545
// Initialize state
4646
int bracketCount = 0;
@@ -56,7 +56,7 @@ private static void RemoveBlock(WordDocument document, WParagraph paragraph, int
5656
{
5757
WParagraph currentParagraph = ownerSection.Paragraphs[i];
5858
// If it's the phrase paragraph, start from the word's position; otherwise, start from the end
59-
int start = i == phraseParaIndex ? phraseEntityIndex : currentParagraph.ChildEntities.Count - 1;
59+
int start = i == phraseParaIndex ? matchWordIndex : currentParagraph.ChildEntities.Count - 1;
6060
// Loop through entities in reverse
6161
for (int j = start; j >= 0; j--)
6262
{
@@ -100,7 +100,7 @@ private static void RemoveBlock(WordDocument document, WParagraph paragraph, int
100100
openingBracketParagraph .ChildEntities.Insert(openingBracketCharIndex, bookmarkStart);
101101
// Create and insert a bookmark end after the specific word
102102
BookmarkEnd bookmarkEnd = new BookmarkEnd(document, bookmarkName);
103-
paragraph.ChildEntities.Insert(phraseEntityIndex + 1, bookmarkEnd);
103+
paragraph.ChildEntities.Insert(matchWordIndex + 1, bookmarkEnd);
104104
// Use Bookmarknavigator to delete content between the bookmarks
105105
BookmarksNavigator navigator = new BookmarksNavigator(document);
106106
navigator.MoveToBookmark(bookmarkName);

0 commit comments

Comments
 (0)