Hello,
I am looking for some guidance. I am trying to find specific tags within a Word document so that I can act/format the document accordingly. For example, there can be a tag [BOLD] This is a test [/BOLD]
where I need to find the start and end tags of [BOLD]
, remove the tags but then format the text in between the tags.
I am using a Regular Expression so that I can capture the begin and end tag versus just trying to find the string value of the tag (since I am formatting).
However when I use this, the ReplacingCallback gets called once but gives me all of the text in Match.Value and shows only one run.
Is there a better way to find text based on a start and end tag and get each instance to work with?
Here is my small code snippet if the FindReplaceOptions
FindReplaceOptions options = new FindReplaceOptions();
options.ReplacingCallback = new ReplaceAndFormatText(options);
wordDoc.Range.Replace(new Regex("\\[BOLD\\].*\\[\\/BOLD\\]"), String.Empty, options);
Here is my ReplacingCallback implementation
private class ReplaceAndFormatText : IReplacingCallback
{
private FindReplaceOptions _options = null;
internal ReplaceAndFormatText(FindReplaceOptions options)
{
_options = options;
}
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args)
{
Console.WriteLine(args.Match.Value);
return ReplaceAction.Skip;
}
}
I can attach a sample Word document but it can be simple as the following
[BOLD]1. [UNDERLINE]Proceeding No.AAAA-0000000000[/UNDERLINE][/BOLD]
title stuff
a. Filing Date and Party:
Description:
Analyst(s):
[BOLD]2. [UNDERLINE]Proceeding No.BBBBB-1111111111[/UNDERLINE][/BOLD]
test test
a. Filing Date and Party:
Description:
Analyst(s):