Hi Team,
I want to find and print the number of occurrences of specific string in word document using aspose.words in java.
I want to search the word “FIGURE” in whole document and print the number of occurrences.
please kindly help me to solve the same issue.
Thanks & Regards,
priyanga G
@priyanga,
Thanks for your inquiry. Please use the following code example to get the desired output.
Document doc = new Document(MyDir + "in.docx");
FindReplaceOptions findReplaceOptions = new FindReplaceOptions();
FindFigureCaption callback = new FindFigureCaption();
findReplaceOptions.setReplacingCallback(callback);
doc.getRange().replace("Figure", "", findReplaceOptions);
System.out.println(callback.mMatchNumber);
class FindFigureCaption implements IReplacingCallback {
public int mMatchNumber;
public int replacing(ReplacingArgs e) throws Exception {
mMatchNumber++;
return ReplaceAction.SKIP;
}
}
Hi @tahir.manzoor,
Thanks a lot.
Its working fine.
Thanks ®ards,
Priyanga G
@priyanga,
Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.
2 posts were split to a new topic: Find the whole word