iglu.util
Class StringTools

java.lang.Object
  |
  +--iglu.util.StringTools

public class StringTools
extends java.lang.Object

Provides utility methods for dealing with Strings.

Author:
Ryan Scherle, Travis Bauer

Constructor Summary
private StringTools()
          Prevent instantiation.
 
Method Summary
static java.lang.String chop(java.lang.String s)
          Removes the last character from a string.
static java.lang.String concat(java.lang.String[] array, char sep)
          Takes an array of strings and concatenates them together, separated by sep
static boolean contains(java.lang.String base, java.lang.String lookFor)
          Returns true if the lookFor string occurs in the base string.
static boolean containsLetter(java.lang.String look)
          Returns true if the given string contains at least one letter.
static long countWords(java.lang.String item)
          Returns the number of words in a string, using IOTools.GENERIC_WORD_DELIMITERS as dividing points between the words.
static java.lang.String dropAll(java.lang.String s1, java.lang.String s2)
          Drops all instances of s2 from s1
static void main(java.lang.String[] args)
          Runs some test examples on the methods of this class.
static java.lang.String[] makeStringArray(java.lang.Object[] a)
          Converts an Object array to a String array.
static java.lang.String removeDelimiters(java.lang.String s)
          Remove all the punctuation, single characters, and white space from the string, using IOTools.GENERIC_WORD_DELIMITERS as the list of things to drop.
static java.lang.String removeDuplicates(java.lang.String s)
          Removes duplicate words from the string and also trims whitespace at the beginning and ending of words.
static java.lang.String removeFirst(java.lang.String base, java.lang.String remove)
          Returns base without remove (only the first occurance is removed).
static java.lang.String removeHtmlTags(java.lang.String original)
          Removes any tags of the form from the string, and replaces them with spaces.
static java.lang.String removeTaggedStrings(java.lang.String source, java.lang.String beginTag, java.lang.String endTag, boolean caseSensitive)
          Removes all the text occuring between the specified tags.
static java.lang.String replaceAll(java.lang.String s1, java.lang.String s2, java.lang.String s3)
          Replace all instances of s2 with s3 in s1
static java.lang.String reverse(java.lang.String st)
          returns the string with the characters reversed
static java.lang.String[] split(java.lang.String s, java.lang.String delimiters)
          Splits a string into pieces according to the delimiters, and returns the pieces in an array.
static java.lang.String[] taggedStrings(java.lang.String source, java.lang.String beginTag, java.lang.String endTag, boolean caseSensitive)
          Returns all of the strings occurring in source between beginTag and endTag.
static void test()
          Runs some tests on this class.
static java.util.HashSet toSet(java.lang.String[] theArray)
          Creates a HashSet from an array of Strings.
static java.lang.String whiteSpaceToSpaces(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTools

private StringTools()
Prevent instantiation.

Method Detail

contains

public static boolean contains(java.lang.String base,
                               java.lang.String lookFor)
Returns true if the lookFor string occurs in the base string.


containsLetter

public static boolean containsLetter(java.lang.String look)
Returns true if the given string contains at least one letter.


countWords

public static long countWords(java.lang.String item)
Returns the number of words in a string, using IOTools.GENERIC_WORD_DELIMITERS as dividing points between the words.


removeFirst

public static java.lang.String removeFirst(java.lang.String base,
                                           java.lang.String remove)
Returns base without remove (only the first occurance is removed). If remove doesn't appear in base, it is returned unchanged.


removeDuplicates

public static java.lang.String removeDuplicates(java.lang.String s)
Removes duplicate words from the string and also trims whitespace at the beginning and ending of words. The string s is assumed to be a list of terms seperated by commas.


chop

public static java.lang.String chop(java.lang.String s)
Removes the last character from a string.


split

public static java.lang.String[] split(java.lang.String s,
                                       java.lang.String delimiters)
Splits a string into pieces according to the delimiters, and returns the pieces in an array.


toSet

public static java.util.HashSet toSet(java.lang.String[] theArray)
Creates a HashSet from an array of Strings. Particularly useful for dealing with the arguments to a main method.


removeHtmlTags

public static java.lang.String removeHtmlTags(java.lang.String original)
Removes any tags of the form from the string, and replaces them with spaces.


dropAll

public static java.lang.String dropAll(java.lang.String s1,
                                       java.lang.String s2)
Drops all instances of s2 from s1

Parameters:
s1 - Source string
s2 - substring to drop

replaceAll

public static java.lang.String replaceAll(java.lang.String s1,
                                          java.lang.String s2,
                                          java.lang.String s3)
Replace all instances of s2 with s3 in s1

Parameters:
s1 - Source string
s2 - String to replace
s3 - What to replace s2 with.

taggedStrings

public static java.lang.String[] taggedStrings(java.lang.String source,
                                               java.lang.String beginTag,
                                               java.lang.String endTag,
                                               boolean caseSensitive)
Returns all of the strings occurring in source between beginTag and endTag. If a tab opens and never closes, the text until the end of the file is included. One use for this class is to get all of the text occurring between and in an HTML document. This would give you all of the boldface text. NOTE: < b > is not the same as in this implementation.


removeDelimiters

public static java.lang.String removeDelimiters(java.lang.String s)
Remove all the punctuation, single characters, and white space from the string, using IOTools.GENERIC_WORD_DELIMITERS as the list of things to drop. Returns a string with all words separated by one space.


whiteSpaceToSpaces

public static java.lang.String whiteSpaceToSpaces(java.lang.String s)

removeTaggedStrings

public static java.lang.String removeTaggedStrings(java.lang.String source,
                                                   java.lang.String beginTag,
                                                   java.lang.String endTag,
                                                   boolean caseSensitive)
Removes all the text occuring between the specified tags. Also removes the tags themselves. Replaces the removed text with a bank space


reverse

public static java.lang.String reverse(java.lang.String st)
returns the string with the characters reversed


concat

public static java.lang.String concat(java.lang.String[] array,
                                      char sep)
Takes an array of strings and concatenates them together, separated by sep

Parameters:
array - a String[] value
sep - a char value
Returns:
a String value

makeStringArray

public static java.lang.String[] makeStringArray(java.lang.Object[] a)
Converts an Object array to a String array.


test

public static void test()
Runs some tests on this class.


main

public static void main(java.lang.String[] args)
Runs some test examples on the methods of this class.