java - Search String in file -


this question has answer here:

i trying count number of times specific string appears file.

this code using:

        while (scanner.hasnext()) {             string nexttoken = scanner.next();             if (nexttoken.equalsignorecase(wordidnamee1))                 count++;         } 

this code counts number of time string appears 'clean', if attached word or followed colon not counted. how can solve problem ?

use contains()

while (scanner.hasnext()) {     string nexttoken = scanner.next();     if (nexttoken.contains(wordidnamee1))         count++; } 

for non case sensitive match:

while (scanner.hasnext()) {         string nexttoken = scanner.next();         if (nexttoken.tolowercase().contains(wordidnamee1.tolowercase()))             count++;     } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -