I have an existing document template with numbered paragraphs.
For example:
1. Some text
2. Some text
3. Some text
3.1 Some sub text
3.2 Some sub text
3.3 Some sub text
4. Some text
I need to generate a new document in which the 3.2, 3.3 and 4 paragraphs should be removed.
I've implemented this in the following way (placed start/end tags around each numbered paragraph to be removed in the existing template document):
- Code: Select all
Regex regEx = new Regex(@"(?<=start)[.\s\S]*(?=end)");
TextSelection[] selections = document.FindPatternInLine(regEx);
while(selections != null){
TextRange range = selections[0].GetAsOneRange();
//Replace with new text
range.Text = "";
range.CharacterFormat.Hidden = true;
selections = document.FindPatternInLine(regEx);
}
document.Replace("start", "", false, true);
document.Replace("end", "", false, true);
The result is that the paragraphs are removed but the numbering stayed intact.
1. Some text
2. Some text
3. Some text
3.1 Some sub text
3.2
3.3
4.
Can you please advice on this? Is there some other way to achieve the desired?
Thank you,
Beatrice