prog.utils
Class StringUtils

java.lang.Object
  |
  +--prog.utils.StringUtils

public class StringUtils
extends java.lang.Object

This class provides static utilities related to Strings and files.


Field Summary
protected static java.lang.String lineend
          A convenience variable.
 
Constructor Summary
StringUtils()
           
 
Method Summary
static void deleteFile(java.io.File file)
          Deletes the file by name.
static void deleteFile(java.lang.String filename)
          Deletes the file by name.
static java.lang.String[] fileToArray(java.io.File filename)
          Loads the lines of a file into an array by way of fileToString() and stringToArray().
static java.lang.String[] fileToArray(java.lang.String filename)
          Loads the lines of a file into an array by way of fileToString() and stringToArray().
static java.lang.String fileToString(java.io.File filename)
          Reads the file into a String and returns the String.
static java.lang.String fileToString(java.lang.String filename)
          Reads the file into a String and returns the String.
static java.lang.String indent(java.lang.String str, int numSpaces)
          Returns a String padded with 'numSpaces' space characters at its start.
static java.lang.String lineendToN(java.lang.String str)
          Returns a copy of the input String where all occurrences of System.getProperty("line.separator") have been replaced with "\n".
static void main(java.lang.String[] args)
           
static java.lang.String replaceText(java.lang.String inStr, java.lang.String before, java.lang.String after)
          Returns a copy of inStr where all occurrences of 'before' have been replaced with 'after'.
static java.lang.String[] stringToArray(java.lang.String str)
          Returns an array of Strings, where each is a portion of the input String up to but not including whatever line endings are present (for example, \n or \r\n).
static void stringToFile(java.lang.String textToWrite, java.io.File filename)
          Writes textToWrite to file without appending.
static void stringToFile(java.lang.String textToWrite, java.io.File filename, boolean append)
          Writes textToWrite to file, where 'append' specifies whether to append to any prior text in the file or rewrite the file.
static void stringToFile(java.lang.String textToWrite, java.lang.String filename)
          Writes textToWrite to file without appending.
static void stringToFile(java.lang.String textToWrite, java.lang.String filename, boolean append)
          Writes textToWrite to file, where 'append' specifies whether to append to any prior text in the file or rewrite the file.
static java.lang.String stripHTML(java.lang.String str)
          Removes the HTML tags from the input string after replacing <p> and <br> with System.getProperty("line.separator").
static java.lang.String toLineend(java.lang.String str)
          Replaces all occurrences of line ending (for example \n or \r\n) with System.getProperty("line.separator").
static java.lang.String weedOutBadChars(java.lang.String inStr)
          Returns a String without these symbols:
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lineend

protected static java.lang.String lineend
A convenience variable.
Constructor Detail

StringUtils

public StringUtils()
Method Detail

weedOutBadChars

public static java.lang.String weedOutBadChars(java.lang.String inStr)
Returns a String without these symbols:
!@#$%^&*()<:,'"  

replaceText

public static java.lang.String replaceText(java.lang.String inStr,
                                           java.lang.String before,
                                           java.lang.String after)
Returns a copy of inStr where all occurrences of 'before' have been replaced with 'after'.

stringToFile

public static void stringToFile(java.lang.String textToWrite,
                                java.io.File filename)
Writes textToWrite to file without appending.
See Also:
stringToFile(String, String)

stringToFile

public static void stringToFile(java.lang.String textToWrite,
                                java.lang.String filename)
Writes textToWrite to file without appending.
See Also:
stringToFile(String, File)

stringToFile

public static void stringToFile(java.lang.String textToWrite,
                                java.io.File filename,
                                boolean append)
Writes textToWrite to file, where 'append' specifies whether to append to any prior text in the file or rewrite the file.
See Also:
stringToFile(String, String, boolean)

stringToFile

public static void stringToFile(java.lang.String textToWrite,
                                java.lang.String filename,
                                boolean append)
Writes textToWrite to file, where 'append' specifies whether to append to any prior text in the file or rewrite the file.
See Also:
stringToFile(String, File, boolean)

lineendToN

public static java.lang.String lineendToN(java.lang.String str)
Returns a copy of the input String where all occurrences of System.getProperty("line.separator") have been replaced with "\n".

stripHTML

public static java.lang.String stripHTML(java.lang.String str)
Removes the HTML tags from the input string after replacing <p> and <br> with System.getProperty("line.separator").

stringToArray

public static java.lang.String[] stringToArray(java.lang.String str)
Returns an array of Strings, where each is a portion of the input String up to but not including whatever line endings are present (for example, \n or \r\n). Exception: if the input String ends with a line ending, the line ending is preserved in the last element of the array.

toLineend

public static java.lang.String toLineend(java.lang.String str)
Replaces all occurrences of line ending (for example \n or \r\n) with System.getProperty("line.separator").

fileToString

public static java.lang.String fileToString(java.io.File filename)
Reads the file into a String and returns the String.
See Also:
fileToString(String)

fileToString

public static java.lang.String fileToString(java.lang.String filename)
Reads the file into a String and returns the String.
See Also:
fileToString(File)

indent

public static java.lang.String indent(java.lang.String str,
                                      int numSpaces)
Returns a String padded with 'numSpaces' space characters at its start.

deleteFile

public static void deleteFile(java.lang.String filename)
Deletes the file by name.
See Also:
deleteFile(File)

deleteFile

public static void deleteFile(java.io.File file)
Deletes the file by name.
See Also:
deleteFile(String)

fileToArray

public static java.lang.String[] fileToArray(java.lang.String filename)
Loads the lines of a file into an array by way of fileToString() and stringToArray().
See Also:
fileToArray(File)

fileToArray

public static java.lang.String[] fileToArray(java.io.File filename)
Loads the lines of a file into an array by way of fileToString() and stringToArray().
See Also:
fileToArray(String)

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException