java - StringUtils.countMatches words starting with a string? -
java - StringUtils.countMatches words starting with a string? -
i'm usingstringutils.countmatches
count word frequencies, there way search text words starting-with characters?
example:
searching art in "artificial fine art in apartment" homecoming 3! need homecoming 2 words starting art only.
my solution replace \r , \n in text space , modify code be:
text = text.replaceall("(\r\n|\n)"," ").tolowercase(); searchword = " "+searchword.tolowercase(); stringutils.countmatches(text, searchword);
i tried next regex:
patternstring = "\\b(" + searchword.tolowercase().trim() + "([a-za-z]*))"; pattern = pattern.compile(patternstring); matcher = pattern.matcher(text.tolowercase());
questions: -does first solution create sense or there improve way this?
-is sec solution faster? i'm working big text files , decent number of search-words.
thanks
text = text.replaceall("(\r\n|\n)"," ").tolowercase(); searchword = " "+searchword.tolowercase(); string[] words = text.split(" "); int count = 0; for(string word : words) if(searchword.length() < word.length()) if(word.substring(word.length).equals(searchword)) count++;
loops provide same effect.
java frequency apache-stringutils
Comments
Post a Comment