We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Count number of match text occurrence

int count = doc.getRange().replace(“hello”, “hello”, options);
without above method how to count occurrence


Thanks for your inquiry. Please use the following code to get desired results. Hope, this helps.

string plainText = doc.Range.Text;
string toBeMatched = "hello";
int totalCount = Regex.Matches(plainText, toBeMatched ).Count;

I am not able to import Range.
image.png (13.8 KB)


Please use updated code to get desired results. Hope, this helps.

String plainText = doc.getRange().getText();
String toBeMatched = "Aspose.Words";

Pattern pattern = Pattern.compile(toBeMatched);
Matcher matcher = pattern.matcher(plainText);
int count = 0;
while (matcher.find()) {
System.out.println("Total Count is: " + count);

thanks . It’s work properly what i am expecting.


Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.