Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe20.iad.POSTED!8ad76e89!not-for-mail From: Arved Sandstrom User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.21) Gecko/20110831 Lightning/1.0b2 Thunderbird/3.1.13 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: contains References: <13987de0-042f-45e7-8279-25e9f7bcfb0e@glegroupsg2000goo.googlegroups.com> In-Reply-To: <13987de0-042f-45e7-8279-25e9f7bcfb0e@glegroupsg2000goo.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Lines: 38 Message-ID: <3n4aq.6818$GV2.28@newsfe20.iad> X-Complaints-To: abuse@newsgroups-download.com NNTP-Posting-Date: Thu, 08 Sep 2011 14:33:35 UTC Organization: Public Usenet Newsgroup Access Date: Thu, 08 Sep 2011 11:33:34 -0300 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7700 On 11-09-08 10:37 AM, Lew wrote: > Arved Sandstrom wrote: >> bob wrote: >>> Is there any case-insensitive version of the String contains method? >>> >> Not that I'm aware of. An easy way to do the deed is to use Pattern; >> something like >> >> boolean isContained = >> Pattern.compile("isThisStringContained", >> Pattern.CASE_INSENSITIVE) >> .matcher("stringThatMayContainOther").find(); >> >> does the trick. >> >> A possibly preferable alternative to doing case-insensitive string >> operations is simply to uppercase (or lowercase) both Strings before >> doing the operation. .toLowerCase() and .toUpperCase() are String >> methods that are available for this purpose. If you plan to do this a >> lot you can write up a small utility method. > > Beware of uppercasing and lowercasing - the results can be surprising. > > String whatThe = "ß".toUpperCase().toLowerCase(); > > What should be the value of '"ß".equalsIgnoreCase("ss")'? > > What should be the value of '"ß".toUpperCase().toLowerCase().equals("ß")'? > That's a good point, but it's no mystery that uppercasing/lowercasing outside the standard 26-letter Latin alphabet has the odd pitfall here and there, like Eszett rules. So my second suggestion applies in particular to Strings that contain Latin characters. For anything else you'd best be aware of the rules and the nature of your text. AHS