com.perdues
Class PString

java.lang.Object
  |
  +--com.perdues.PString

public class PString
extends java.lang.Object

Static utility methods involving Strings.


Method Summary
static java.lang.String after(java.lang.String subject, java.lang.String delimiter)
          Returns a suffix of the subject, starting just after the first occurrence of the delimiter string.
static java.lang.String afterLast(java.lang.String subject, java.lang.String delimiter)
          Returns a suffix of the subject, starting just after the last occurrence of the delimiter string.
static int intValue(java.lang.String s, int dfault)
          Returns the decimal integer value represented by the String, or the given default if the string is null or its format is bad.
static void main(java.lang.String[] args)
          For testing.
static java.lang.String padLeft(java.lang.String s, int width, char c)
          Pad a string on the left to the specified width in characters, using the specified pad character and returning the string with added padding.
static java.lang.String padRight(java.lang.String s, int width, char c)
          Pad a string on the right to the specified width in characters, using the specified pad character and returning the string with added padding.
static java.lang.String readAll(java.io.InputStream ins)
          Read all remaining input from the InputStream through the default character encoding, and return it as a String.
static java.lang.String readAll(java.io.Reader reader)
          Reads all remaining input from the Reader and returns it as a String.
static java.lang.String readAll(java.net.URL url)
          Reads and returns the contents of a URL as a String.
static java.lang.String subst(java.lang.String subject, java.lang.String old, java.lang.String nu)
          Substitute a new value in place of all occurrences one substring within a subject string.
static java.lang.String toString(java.lang.Object o)
          Same as object.toString() except for arrays, which come out as "{a[1],a[2],...}".
static java.lang.String upTo(java.lang.String subject, java.lang.String delimiter)
          Returns a prefix of subject, up to the first occurrence of the delimiter string, or the entire subject if the delimiter is not found.
static java.lang.String upToLast(java.lang.String subject, java.lang.String delimiter)
          Returns a prefix of subject, up to the last occurrence of the delimiter string, or the entire subject if the delimiter is not found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toString

public static java.lang.String toString(java.lang.Object o)
Same as object.toString() except for arrays, which come out as "{a[1],a[2],...}". The object may be null, which converts to "null".

intValue

public static int intValue(java.lang.String s,
                           int dfault)
Returns the decimal integer value represented by the String, or the given default if the string is null or its format is bad.

upTo

public static java.lang.String upTo(java.lang.String subject,
                                    java.lang.String delimiter)
Returns a prefix of subject, up to the first occurrence of the delimiter string, or the entire subject if the delimiter is not found.

upToLast

public static java.lang.String upToLast(java.lang.String subject,
                                        java.lang.String delimiter)
Returns a prefix of subject, up to the last occurrence of the delimiter string, or the entire subject if the delimiter is not found.

after

public static java.lang.String after(java.lang.String subject,
                                     java.lang.String delimiter)
Returns a suffix of the subject, starting just after the first occurrence of the delimiter string. If the delimiter is not found, returns the entire subject without copying it.

afterLast

public static java.lang.String afterLast(java.lang.String subject,
                                         java.lang.String delimiter)
Returns a suffix of the subject, starting just after the last occurrence of the delimiter string. If the delimiter is not found, returns the entire subject without copying it.

padRight

public static java.lang.String padRight(java.lang.String s,
                                        int width,
                                        char c)
Pad a string on the right to the specified width in characters, using the specified pad character and returning the string with added padding. Never truncate.

padLeft

public static java.lang.String padLeft(java.lang.String s,
                                       int width,
                                       char c)
Pad a string on the left to the specified width in characters, using the specified pad character and returning the string with added padding. Never truncate.

subst

public static java.lang.String subst(java.lang.String subject,
                                     java.lang.String old,
                                     java.lang.String nu)
Substitute a new value in place of all occurrences one substring within a subject string.

readAll

public static java.lang.String readAll(java.io.InputStream ins)
                                throws java.io.IOException
Read all remaining input from the InputStream through the default character encoding, and return it as a String.

readAll

public static java.lang.String readAll(java.io.Reader reader)
                                throws java.io.IOException
Reads all remaining input from the Reader and returns it as a String.

readAll

public static java.lang.String readAll(java.net.URL url)
                                throws java.io.IOException
Reads and returns the contents of a URL as a String. The content should be of some text type, e.g. text/plain or text/html. This uses Java's default encoding to convert bytes to characters.

main

public static void main(java.lang.String[] args)
For testing.