Re: what is the quickest way to find out whether a string contains another string?
- From: Chris Smith <cdsmith@xxxxxxx>
- Date: Mon, 5 Dec 2005 12:47:18 -0700
Rhino <no.offline.contact.please@xxxxxxxxxx> wrote:
> One approach would be to use "regular expressions", often abbreviated
> "regexp". If you look at the Pattern class in the J2SE API, you'll find an
> overview describing how to use them.
Why would anyone want to use regular expressions to look for a plain
String? Regular expressions are a tool for deciding whether a String or
some subset thereof matches a defined regular language. Although string
searching is a trivial degeneration of the problem addressed by regular
expressions, there's no need to introduce the added complexity.
If you are set on using regular expressions, converting the arbitrary
input string into a pattern that matches only itself is the first task.
Prior to Java 1.5, this was very difficult. In 1.5, it's encapsulated
in a method called Pattern.quote(String). Once that's done, you can
search for that pattern. It's far easier, though, to use String.indexOf
(prior to 1.5) or String.contains (as of 1.5).
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
.
- Follow-Ups:
- References:
- Prev by Date: Re: WIKI based language??
- Next by Date: Re: Detecting virtual IP addresses
- Previous by thread: Re: what is the quickest way to find out whether a string contains another string?
- Next by thread: Re: what is the quickest way to find out whether a string contains another string?
- Index(es):
Relevant Pages
|