Re: what is the quickest way to find out whether a string contains another string?



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
.



Relevant Pages

  • Re: ACT scripting
    ... While executing the the script send by you..I am getting the following ... > 1) Assuming the pattern you are looking for is unique in the file, ... > 'string to search ... > Regular Expressions. ...
    (microsoft.public.scripting.vbscript)
  • Re: Pattern Match
    ... Is there any way to get them in one pattern? ... Here's a demo program I use to test out regular expressions. ... quotes if the expression has spaces) and a string to test (again ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: BInding operator fails
    ... you're looking for $rdns inside of $result. ... looking for any of the whitespace in your pattern. ... you have no reason to be using regular expressions. ... If you just want to see if one string is ...
    (perl.beginners)
  • Re: RegExp irregularity in JScript
    ... using Regular Expressions to do it. ... takes a pattern and an string, and tells us whether the string matches the ... pattern when the user clicks a button. ... But - when we validate some strings using this code, ...
    (microsoft.public.scripting.jscript)
  • Re: (Unsure where to post)
    ... > What is an efficient algorithm for searching a large string (a block of ... > memory that's 10-20mb in size) for a varying number of strings, ... How many don't-care symbols do you have in a typical pattern? ...
    (comp.theory)