How to use Contains - without case sensitivity?
Hello everyone,
I just registered here now that I'm working on my first "real world" (not book driven) application and I'm stuck with case sensitivity:
Code:
// Names holds the names I want to search for.
Set Names = new HashSet<String>();
// (Names is populated by a SQL result set)
// wordlist contains the words from a page of text that I have pulled from a file:
List<String> wordlist = stringToArrayList(pagetext, " ");
for (String word: wordlist)
{
System.out.print(word + "\t");
if (Names.contains(word))
{
System.out.print("Name Found.\n");
}
}
It is clear that Names.contains() is case sensitive, but I can't find an "ignore case" or "case insensitive" version - though it seems this should be common enough to be included somewhere. Can you nudge me in the right direction?
Thanks,
Russell
Re: How to use Contains - without case sensitivity?
Quote:
Originally Posted by
Russell411
Hi Jos,
1. I'm scanning tens of thousands of files, so speed is a concern - more concerning is that I'm not clear on "Comparator<String>" - going to have to read. This seems like the best solution, so I've gotta go figure out how to do it.
2. Another technique I'm not familiar with - I have no idea how I'd do this.
3. Hmmm... I can probably do this - but I don't like the result: having no case in my dataset any longer - Maybe I can make a copy of each dataset to run together and use an iterator to retrieve the "non-case-corrected" version.
Seems like such a trivial task has become a lot of study. :frusty:
Thanks,
Russell
org.apache.commons.lang.StringUtils.containsIgnore Case("AbBaCca", "bac");
use commons api provided by apache.
I also faced this problem and i solved this using the above api.
Now i think it may be proved useful information for you.
Thanks for the quick reply... But I've gotta say, "Yuck!"