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
Post a Comment