I have an external file named quotes.txt and I'll show you some contents of the file:
1 Everybody's always telling me one thing and out the other.
2 I love criticism just so long as it's unqualified praise.
3 The difference between 'involvement' and 'commitment' is like an eggs-and-ham
breakfast: the chicken was 'involved' - the pig was 'committed'.
I used this: StringTokenizer str = new StringTokenizer(line, " .'");
This is the code for the searching:
String line = "";
boolean wordFound = false;
while((line = bufRead.readLine()) != null) {
while(str.hasMoreTokens()) {
String next = str.nextToken();
if(next.equalsIgnoreCase(targetWord) {
wordFound = true;
output = line;
break;
}
}
if(wordFound) break;
else output = "Quote not found";
}
Now, I want to search for strings "Everybody's"
and "it's"
in line 1 and 2 but it won't work since the apostrophe is one of the delimiters. If I remove that delimiter, then I won't be able to search for "involvement"
, "commitment"
, "involved"
and "committed"
in line 3.
What suitable code can I do with this problem? Please help and thanks.