Hi;
How can I replace with only the first word found in my document?
Hi;
How can I replace with only the first word found in my document?
Hi
Thank you for your interest in Aspose products. I think that you can try using ReplaceEvaluator to achieve this. For example see the following code.
public void TestReplace_103749()
{
Document doc = new Document(@"253_103749_ladybug\in.doc");
Regex regex = new Regex("Test");
doc.Range.Replace(regex, new ReplaceEvaluator(ReplaceAction_103749), true);
doc.Save(@"253_103749_ladybug\out.doc");
}
int replaceCount = 0;
ReplaceAction ReplaceAction_103749(object sender, ReplaceEvaluatorArgs e)
{
e.Replacement = "Some text";
if (replaceCount == 0)
{
replaceCount++;
return ReplaceAction.Replace;
}
else
{
return ReplaceAction.Stop;
}
}
I hope that this will help you.
Please let me know if you would like to know something else.
Best regards.