com.mindprod.common15
Class StringSearch

java.lang.Object
  extended by com.mindprod.common15.StringSearch

public class StringSearch
extends java.lang.Object

Methods for searching strings for multiple targets. Especially useful for screenscraping.

to seach for "apple", "pear" or "cherry" all in one go. Methods use ... notation only available in JDK 1.5+.

Since:
2005-01-01
Version:
1.0 2005-01-01 initial version
Author:
Roedy Green, Canadian Mind Products

Constructor Summary
StringSearch()
           
 
Method Summary
static int indexOf(java.lang.String s, int base, java.lang.String... targets)
          find first of a number of possible targets.
static int indexOf(java.lang.String s, java.lang.String... targets)
          find first of a number of possible targets.
static int indexOfEnd(java.lang.String s, int base, java.lang.String... targets)
          find first of a number of possible targets
static int indexOfEnd(java.lang.String s, java.lang.String... targets)
          find first of a number of possible targets
static int lastIndexOf(java.lang.String s, int base, java.lang.String... targets)
          find last of a number of possible targets, one closest to the end
static int lastIndexOf(java.lang.String s, java.lang.String... targets)
          find last of a number of possible targets, one closest to the end
static int lastIndexOfEnd(java.lang.String s, int base, java.lang.String... targets)
          find last of a number of possible targets, one closest to the end
static int lastIndexOfEnd(java.lang.String s, java.lang.String... targets)
          find last of a number of possible targets, one closest to the end
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringSearch

public StringSearch()
Method Detail

indexOf

public static int indexOf(java.lang.String s,
                          java.lang.String... targets)
find first of a number of possible targets.

Parameters:
s - String to search in
targets - multiple targets to search for
Returns:
index of the first matching target, -1 if none of the targets match.

indexOf

public static int indexOf(java.lang.String s,
                          int base,
                          java.lang.String... targets)
find first of a number of possible targets.

Parameters:
s - String to search in
base - offset where to start looking
targets - multiple targets to search for
Returns:
index of the first matching target, -1 if none of the targets match.

indexOfEnd

public static int indexOfEnd(java.lang.String s,
                             java.lang.String... targets)
find first of a number of possible targets

Parameters:
s - String to search in
targets - multiple targets to search for
Returns:
index of char one past the end of the first matching target, -1 if none of the targets match.

indexOfEnd

public static int indexOfEnd(java.lang.String s,
                             int base,
                             java.lang.String... targets)
find first of a number of possible targets

Parameters:
s - String to search in
base - offset where to start looking
targets - multiple targets to search for
Returns:
index of char one past the end of the first matching target, -1 if none of the targets match.

lastIndexOf

public static int lastIndexOf(java.lang.String s,
                              java.lang.String... targets)
find last of a number of possible targets, one closest to the end

Parameters:
s - String to search in
targets - multiple targets to search for
Returns:
index of the first matching target, -1 if none of the targets match.

lastIndexOf

public static int lastIndexOf(java.lang.String s,
                              int base,
                              java.lang.String... targets)
find last of a number of possible targets, one closest to the end

Parameters:
s - String to search in
base - offset where to start looking
targets - multiple targets to search for
Returns:
index of the first matching target, -1 if none of the targets match.

lastIndexOfEnd

public static int lastIndexOfEnd(java.lang.String s,
                                 java.lang.String... targets)
find last of a number of possible targets, one closest to the end

Parameters:
s - String to search in
targets - multiple targets to search for
Returns:
index of the char one past the matching target that starts closest to the end, -1 if none of the targets match.

lastIndexOfEnd

public static int lastIndexOfEnd(java.lang.String s,
                                 int base,
                                 java.lang.String... targets)
find last of a number of possible targets, one closest to the end

Parameters:
s - String to search in
base - offset where to start looking
targets - multiple targets to search for
Returns:
index of the char one past the matching target that starts closest to the end, -1 if none of the targets match.