MDi JLib
1.7.4

com.microdeveloper.common
Class Str

java.lang.Object
  extended by com.microdeveloper.common.Str

public class Str
extends Object

Provides extensive String manipulation, extensions, utilities, and new capabilities.

This class attempts to provide all of the functionality found in both String and StringBuffer, plus provide a wide collection of additional functionality.

If an Str object is appended and needs to grow beyond its current size, it will do so without programmer intervention. It also keeps a little extra buffer of size to accomodate small amounts of growth without needing memory re-allocation.

Since:
1.0
Version:
1.3
Author:
MicroDeveloper, Inc.

Constructor Summary
Str()
          The object has memory allocated to store an average size string.
Str(char[] c)
          The object is inititialized to have an exact copy of the character array.
Str(int initialSize)
          Set the object to have an initial capacity.
Str(int initialSize, int initialExtra)
          Create an object with a specific initial capacity and to be able to grow by a specific increment.
Str(Str s)
          A new object is created that is an exact copy of the provided Str object.
Str(String s)
          A new object is created that contains a copy of the provided String object.
 
Method Summary
 Str after(int index)
          Get all of the substring that occurs after a particular character.
static String after(String s, int index)
          Get all of the substring that occurs after a particular character.
 void append(char c)
          Add one character to the end of the string.
 void append(Str s)
          Append a string on to the end of your string.
 void append(String s)
          Append a string on to the end of your string.
static int Ascii(char c)
          Method Ascii returns the decimal representation of the character given.
static double atod(String s)
          Like the ANSI c function atod().
static int atoi(char c)
          Sort of like the ANSI c function atoi().
static int atoi(String s)
          Like the ANSI c function atoi().
 Str before(int index)
          Get all of the substring that occurs before a particular character.
static String before(String s, int index)
          Get all of the substring that occurs before a particular character.
 void center(int newLen)
          Try to center the text in a pad of spaces.
static String center(String s, int newLen)
          Try to center the text in a pad of spaces.
 char charAt(int Index)
          Used for compatibility with String and StringBuffer.
 int charCount(char c)
          Count how many times a particular character occurs within your string.
static String CharToHex(char c)
          Method CharToHex converts a character to a hexidecimal String that represents the characters ASCII integer representation.
static int CharToInt(char c)
          Method CharToInt returns the decimal representation of the character given.
static char Chr(int i)
          Method Chr returns the ASCII character with is the binary equivelant to the integer given.
static String commaStr(double val)
          Converts a double to a string with commas inserted for thousands, millions, etc.
 int compareTo(Str s)
          A string comparison method that returns a numeric result.
 int compareTo(String s)
          A string comparison method that returns a numeric result.
 int countDigits()
          Counts the number of digits in this.
 int countRange(char low, char high)
          Determines the number of digits that occur within the given range within this.
 void delete(int index, int howMany)
          Remove characters from your string.
 void deleteFirst()
          Remove first character from the beginning of your string.
 void deleteFirst(int howMany)
          Remove characters from the beginning of your string.
 void deleteLast()
          Remove the last character from the end of your string.
 void deleteLast(int howMany)
          Remove characters from the end of your string.
 boolean endsWith(String s)
          Does the string object end with this bit of text.
 boolean eq(Str s)
          Test for equality between your string and the string in s.
 boolean eq(String s)
          Test for equality between your string and the string in s.
static boolean equal(String[] s1, String[] s2)
          Uses String.equals(), but will consider that either or both arrays/strings might be null.
static boolean equal(String s1, String s2)
          Uses String.equals(), but will consider that either or both strings might be null.
 boolean equals(Object obj)
          Compares equality with the object given
 Str extractWord()
          Extract and return the first word.
 int firstDigit()
          Returns the index of the first digit, or returns -1 if there are no digits.
 void forceNumeric()
          Force string to be the first number found.
static String formatDouble(double d, int decimalPlaces)
          Converts a double to a string with a specified number of decimal places.
 Str from(int index)
          Get all of the substring that occurs from a particular character to the end of the string.
static String from(String s, int index)
          Get all of the substring that occurs from a particular character to the end of the string.
 boolean ge(Str s)
          Test for "greater than or equal to" between your string and the string in s.
 boolean ge(String s)
          Test for "greater than or equal to" between your string and the string in s.
 char get(int Index)
          Retrieve a copy of one character.
 Str get(int index, int length)
          Retrieve a copy of a substring.
 int getCapacity()
          Get the number of characters this object can hold without doing a reallocation.
static char getChar(String s, int index)
          Just like String.charAt() except for null strings or for strings that are too short, an exception will not be thrown and instead, a null char will be returned.
 String getCr()
          Returns the current carriage return value.
 int getDefaultWrapPoint()
          Returns the default wrap point property
 char getLast()
          Retrieve a copy of the last character.
 boolean gt(Str s)
          Test for "greater than" between your string and the string in s.
 boolean gt(String s)
          Test for "greater than" between your string and the string in s.
 int hashCode()
          Return this as a hashcode
static char HexToChar(String hex)
          Method HexToChar converts a 2-byte hexidecimal String to the ASCII character that it represents.
static int HexToInt(String hex)
          Method HexToInt converts an hexidecimal String to a integer.
 String HexToString()
          Method HexToString non-static version of HexToString
 String HexToString(boolean pad)
          Method HexToString non-static version of HexToSring.
static String HexToString(String hex)
          Method HexToString converts a Hexidecimal string to an ASCII string.
static String HexToString(String hex, boolean pad)
          Method HexToString converts a Hexidecimal string to an ASCII string.
 String indent(int indentAmount, char indentChar)
          Indents a string s using character indentChar by int len
static String indent(String s, int indentAmount, char indentChar)
          Indents a string s using character indentChar by int len
 int indexOf(char c)
          Find the position within your string of a particular character.
 int indexOf(char c, int startPos)
          Find the position within your string of a particular character.
 int indexOf(String s)
          Find the position within your string of a particular sequence of characters.
 int indexOf(String s, int startPos)
          Find the position within your string of a particular sequence of characters.
 int indexOfIgnoreCase(char c)
          Find the position within your string of a particular character, ignoring case.
 int indexOfIgnoreCase(char c, int startPos)
          Find the position within your string of a particular character, ignoring case.
 int indexOfIgnoreCase(String s)
          Find the position within your string of a particular sequence of characters, ignoring case.
 int indexOfIgnoreCase(String s, int startPos)
          Find the position within your string of a particular sequence of characters, ignoring the case.
 void insert(char c, int index)
          Insert a character immediately before a particular character.
 void insert(String s, int index)
          Insert a String object immediately before a particular character.
 void insert(Str s, int index)
          Insert a Str object immediately before a particular character.
static char IntToChar(int i)
          Method IntToChar returns the ASCII character with is the binary equivelant to the integer given.
static String IntToHex(int i)
          Method IntToHex converts an integer to a hexidecimal String.
 boolean isLower(int index)
          Is char at index lower case?
 boolean isUpper(int index)
          Is char at index upper case?
static String labelString(String s, char labelChar, int wrapWidth, boolean encase)
          Generates a centered 1 or 3 line label for text outputs.
 int lastIndexOf(char c)
          Returns the last index of this where the given char is found starting from the end of the String.
 boolean le(Str s)
          Test for "less than or equal to" between your string and the string in s.
 boolean le(String s)
          Test for "less than or equal to" between your string and the string in s.
 void left(int newLen)
          Force the length of the string and keep text to the left.
static String left(String s, int newLen)
          Force the length of the string and keep text to the left.
 int leftSpaceCount()
          Report how many leading spaces there are.
 int length()
          Get the current length of your string - not the same as the amount of memory allocated.
 String lpad(int l, char c)
          Left pads this Str with Char c out to length Int l.
static String lpad(String s, int len, char c)
          Left pads String s with Char c out to length Int len.
 boolean lt(Str s)
          Test for "less than" between your string and the string in s.
 boolean lt(String s)
          Test for "less than" between your string and the string in s.
static String moneyStr(double d)
          Converts a double to a string with two decimal places.
 boolean ne(Str s)
          Test for "not equal" between your string and the string in s.
 boolean ne(String s)
          Test for "not equal" between your string and the string in s.
static String normalize(Object s)
          Return a string that is not null.
static String nowStr()
          Get the current local date and time.
static String pad(char c, int l)
          Creates a string of characters to a given length for use in padding.
 String pad(int l)
          Returns a padded string with a length of int len comprised of char c.
 char pop()
          If you wish to treat your string like a stack, you can push and pop characters.
 void push(char c)
          If you wish to treat your string like a stack, you can push and pop characters.
 void removeDoubleSpaces()
          Eliminate all occurances of two more space in a row.
 void replace(char c1, char c2)
          Replace all instances of one character with another character.
 void replace(char c, String s)
          Replace all instances of one character with a String object.
 void replace(String s, char c)
          Search for a particular character sequence and replace it with one character.
 void replace(String s1, String s2)
          Search for a particular character sequence and replace it with a different character sequence.
 void reverse()
          Reverse the order of all the characters.
 void right(int newLen)
          Force the length of the string and keep text to the right.
static String right(String s, int newLen)
          Force the length of the string and keep text to the right.
 int rightSpaceCount()
          Report how many trailing spaces there are.
 String rpad(int l, char c)
          Right pads current Str with Char c out to length Int len.
static String rpad(String s, int len, char c)
          Right pads String s with Char c out to length Int len.
 void set(int index, char c)
          Set one character in the string.
 void set(Str s)
          Force the contents of this object to be the same as another Str object.
 void set(String s)
          Force the contents of this object to be the same as a String object.
 void setCapacity(int howMuch)
          Force this object to be able to hold a specific number of characters without reallocation.
 void setCharAt(int index, char c)
          Provided for compatibility with StringBuffer.
 void setCr(String c)
          Sets the carriage return property to the given String value.
 void setDefaultWrapPoint(int n)
          Sets the default wrap point property
 void setExtra(int howMuch)
          Set how much extra to grow when growth is needed.
 void setLength(int newLen)
          Force the length of your string.
 void setSpacer(char c)
          Set the spacer character property
 String spacer()
          Establishes and converts the spacing character to a string.
static String spacer(char c)
          Returns the a char spacer as a String
static Str spaces(int quan)
          Create a Str object containing nothing but a quantity of spaces.
 boolean startsWith(String s)
          Test to see if your string begins with a specific sequence of characters.
static Str stringOf(int quan, char c)
          Create a Str object containing nothing but a quantity of one character.
 String StringToHex()
          Method StringToHex the non-static version of StringToHex()
 String StringToHex(boolean pad)
          Method StringToHex non-static version of StringToHex
static String StringToHex(String s)
          Method StringToHex converts a String object to a Hexidecimal version of the String object.
static String StringToHex(String s, boolean pad)
          Method StringToHex converts a String object to a Hexidecimal version of the String object.
 Str substring(int index, int length)
          Provided for compatibility with String and StringBuffer and the case mixing Sun provides.
 Str subString(int index, int length)
          Provided for compatibility with String and StringBuffer and the case mixing many people expect.
static String substring(String s, int index, int length)
          Same as substring but uses mixed case nomenclature.
static String subString(String s, int index, int length)
          An improved String substring method that returns a portion of the given String.
 Str through(int index)
          Get all of the substring that occurs through a particular character.
static String through(String s, int index)
          Get all of the substring that occurs through a particular character.
static boolean toBoolean(String s)
          Try to convert a string to a boolean value.
 char[] toCharArray()
          Generate a character array that contains a copy of the string.
 double toDouble()
          Try to convert this string to a double value.
static double toDouble(String s)
          Try to convert a string to a double value.
 int toInt()
          Try to convert this string to an integer value.
static int toInt(String s)
          Try to convert a string to an integer value.
static int[] toIntArray(String[] values)
          The inverse of toStringArray, builds a array of integers from an array of Strings.
 long toLong()
          Try to convert this string to a long value.
static long toLong(String s)
          Try to convert a string to a long value.
 void toLower()
          All characters are forced to lower case.
 void toLower(int index)
          Char at index is forced to lower case.
 String toString()
          Convert this Str object to a String object.
static String[] toStringArray(int[] values)
          Converts a series of integers to a series of corresponding Strings.
static Timestamp toTimestamp(String s)
          Try to convert a string to a Timestamp object.
 void toUpper()
          All characters are forced to upper case.
 void toUpper(int index)
          Char at index is forced to upper case.
 Vector toVector(char delimiter)
          Method toVector converts a delimited representation into a vector of separate values.
static Vector toVector(String s)
          Convenience method variant of toVector that converts a comma delimited String into a vector of separate values.
static Vector toVector(String s, char delimiter)
          Method toVector converts a delimited String into a vector of separate values.
 int trailingDigits()
          Count the number of trailing digits.
static int trailingDigits(String s)
          Count the number of trailing digits in the given String.
 void trim()
          Trims all leading spaces and all trailing spaces.
static String trim(String s)
          Return a string that is either null or has at least one character.
 void trimLead()
          Trims all leading spaces, no trailing spaces.
 void trimLeadWhitespace()
          Trims all leading spaces, newlines, returns and tabs.
 void trimTrail()
          Trims all trailing spaces, no leading spaces.
 void trimTrailTo(char c)
          Trims all characters from end of the string until a particular character is encountered.
 void trimTrailWhitespace()
          Trims all trailing spaces, newlines, returns and tabs.
 void trimWhitespace()
          Trims all leading spaces, newlines, returns and tabs and all trailing spaces, newlines, returns and tabs.
static String trimWhitespace(String s)
          Removes all whitespace from the given String.
static boolean usable(String s)
          Determines if the given String is useable.
static Str verboseMoney(double x)
          Convert a double to English ( 12.01 -> "twelve and 01/100" ).
 String wrap()
          Wraps String s at position 80 using line terminator ascii 13 + ascii 11.
 String wrap(int l)
          Wraps String s at break position int len using line terminator ascii 13 + ascii 11.
 String wrap(int l, String c)
          Wraps String s at wrap position int len using line terminator String cr.
 String wrap(int l, String c, int indentAmount, char indentChar)
          Wraps String s at position int len using line terminator String cr with indent character indentChar indented to indentAmount.
static String wrap(String s)
          Wraps String s at position 80 using line terminator ascii 13 + ascii 11.
static String wrap(String s, int len)
          Wraps String s at break position int len using line terminator ascii 13 + ascii 11.
static String wrap(String s, int l, String c)
          Wraps String s at wrap position int len using line terminator String cr.
static String wrap(String s, int l, String c, int indentAmount, char indentChar)
          Wraps String s at position int len using line terminator String cr with indent character indentChar indented to indentAmount.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Str

public Str(int initialSize)
Set the object to have an initial capacity.

Parameters:
initialSize - How many characters the object can initially hold.


Str

public Str(int initialSize,
           int initialExtra)
Create an object with a specific initial capacity and to be able to grow by a specific increment.

Parameters:
initialSize - How many characters the object can initially hold.

initialExtra - How many characters the object will grow by when more memory is needed.


Str

public Str()
The object has memory allocated to store an average size string.


Str

public Str(char[] c)
The object is inititialized to have an exact copy of the character array. Enough memory is allocated for some growth.

Parameters:
c - the character array to copy.


Str

public Str(Str s)
A new object is created that is an exact copy of the provided Str object.

Enough memory is allocated for some growth.

Parameters:
s - The Str object to copy.


Str

public Str(String s)
A new object is created that contains a copy of the provided String object. Enough memory is allocated for some growth.

Parameters:
s - The String object to copy.

Method Detail

set

public void set(Str s)
Force the contents of this object to be the same as another Str object.

Parameters:
s - The Str object to copy.


set

public void set(String s)
Force the contents of this object to be the same as a String object.

Parameters:
s - The String object to copy.


length

public int length()
Get the current length of your string - not the same as the amount of memory allocated.

Works just like the length() methods in String and StringBuffer.

Returns:
The current string length.


setLength

public void setLength(int newLen)
Force the length of your string.

If you want to empty your string, use setLength(0);

If you specify a number that is longer than the current string length, the new characters will be null characters.

Parameters:
newLen - what you want the new length of your string to be.


compareTo

public int compareTo(Str s)
A string comparison method that returns a numeric result.

A lot like the ANSI strcmp() function.

Parameters:
s - The Str object to compare to.

Returns:
0 If this is equal to s, a negative value if this is less than s, a positive value if this is greater than s.


compareTo

public int compareTo(String s)
A string comparison method that returns a numeric result.

A lot like the ANSI strcmp() function.

Parameters:
s - the String object to compare to.

Returns:
0 if this is equal to s, a negative value if this is less than s, a positive value if this is greater than s.


eq

public boolean eq(Str s)
Test for equality between your string and the string in s.

This method is case sensitive.

Parameters:
s - The Str object to compare to.

Returns:
True if s is identical.


eq

public boolean eq(String s)
Test for equality between your string and the string in s.

This method is case sensitive.

Parameters:
s - The String object to compare to.

Returns:
True if s is identical.


ne

public boolean ne(Str s)
Test for "not equal" between your string and the string in s.

This method is case sensitive.

Parameters:
s - The Str object to compare to.

Returns:
False if s is identical.


ne

public boolean ne(String s)
Test for "not equal" between your string and the string in s.

This method is case sensitive.

Parameters:
s - The String object to compare to.

Returns:
False if s is identical.


lt

public boolean lt(Str s)
Test for "less than" between your string and the string in s.

This method is case sensitive.

Parameters:
s - The Str object to compare to.

Returns:
True if your string is "less than" s.


lt

public boolean lt(String s)
Test for "less than" between your string and the string in s.

This method is case sensitive.

Parameters:
s - The String object to compare to.

Returns:
True if your string is "less than" s.


le

public boolean le(Str s)
Test for "less than or equal to" between your string and the string in s.

This method is case sensitive.

Parameters:
s - The Str object to compare to.

Returns:
True if your string is "less than or equal to" s.


le

public boolean le(String s)
Test for "less than or equal to" between your string and the string in s.

This method is case sensitive.

Parameters:
s - The String object to compare to.

Returns:
True if your string is "less than or equal to" s.


ge

public boolean ge(Str s)
Test for "greater than or equal to" between your string and the string in s.

This method is case sensitive.

Parameters:
s - The Str object to compare to.

Returns:
True if your string is "greater than or equal to" s.


ge

public boolean ge(String s)
Test for "greater than or equal to" between your string and the string in s.

This method is case sensitive.

Parameters:
s - The String object to compare to.

Returns:
True if your string is "greater than or equal to" s.


gt

public boolean gt(Str s)
Test for "greater than" between your string and the string in s.

This method is case sensitive.

Parameters:
s - The Str object to compare to.

Returns:
True if your string is "greater than" s.


gt

public boolean gt(String s)
Test for "greater than" between your string and the string in s.

This method is case sensitive.

Parameters:
s - The String object to compare to.

Returns:
True if your string is "greater than" s.


setExtra

public void setExtra(int howMuch)
Set how much extra to grow when growth is needed.

Smaller values will usually save memory, but frequent reallocation may take a lot of time.

Parameters:
howMuch - The number of extra characters to allocate when memory reallocation is required. Values must be greater than zero.


getCapacity

public int getCapacity()
Get the number of characters this object can hold without doing a reallocation.

Returns:
The number of characters this object can currently hold without reallocation.


setCapacity

public void setCapacity(int howMuch)
Force this object to be able to hold a specific number of characters without reallocation.

Any attempt to make the string grow bigger than this size will succeed.

Setting the capacity to be smaller than the current string size will result in trailing characters being clipped.

Parameters:
howMuch - How many characters will be the new capacity.


get

public char get(int Index)
Retrieve a copy of one character.

Parameters:
Index - Which character (0 is the first character).

Returns:
The retrieved character. Returns a null character if Index is outside of 0..length.


getLast

public char getLast()
Retrieve a copy of the last character.

Returns:
The retrieved character. Returns a null character if the string is empty.


charAt

public char charAt(int Index)
Used for compatibility with String and StringBuffer.

see get().

Parameters:
Index - position within
Returns:
character at the given position

get

public Str get(int index,
               int length)
Retrieve a copy of a substring.

Parameters:
index - The character of the substring.

length - The length of the substring. Specifying a substring beyond the end of the string will return as much of the string as possible.

Returns:
A Str object containing the substring.


subString

public Str subString(int index,
                     int length)
Provided for compatibility with String and StringBuffer and the case mixing many people expect.

Parameters:
index - starting index point
length - length of string to return
Returns:
chunk of string

substring

public Str substring(int index,
                     int length)
Provided for compatibility with String and StringBuffer and the case mixing Sun provides.

Parameters:
index - starting index point
length - length of string to return
Returns:
chunk of string

before

public Str before(int index)
Get all of the substring that occurs before a particular character.

Parameters:
index - The character that marks the end of the substring. This character is not included in the substring.

Returns:
A Str object containing the substring.


through

public Str through(int index)
Get all of the substring that occurs through a particular character.

Parameters:
index - The character that marks the end of the substring. This character is included in the substring.

Returns:
A Str object containing the substring.


after

public Str after(int index)
Get all of the substring that occurs after a particular character.

Parameters:
index - The character that marks the beginning of the substring. This character is not included in the substring.

Returns:
A Str object containing the substring.


from

public Str from(int index)
Get all of the substring that occurs from a particular character to the end of the string.

Parameters:
index - The character that marks the beginning of the substring. This character is included in the substring.

Returns:
A Str object containing the substring.


toCharArray

public char[] toCharArray()
Generate a character array that contains a copy of the string.

Returns:
A new char array.


set

public void set(int index,
                char c)
Set one character in the string.

Parameters:
index - Which character to set. If index references a character beyond the last character of the string, the string will be lengthened and the last character will be set appropriately (undefined characters will be set to a null character).

c - The character to be placed at index.


setCharAt

public void setCharAt(int index,
                      char c)
Provided for compatibility with StringBuffer.

Parameters:
index - index of the position to use
c - a character to set at the given index position

append

public void append(char c)
Add one character to the end of the string.

Parameters:
c - The character to append to the end of the string.


append

public void append(Str s)
Append a string on to the end of your string.

Parameters:
s - The Str object to be appended.


append

public void append(String s)
Append a string on to the end of your string.

Parameters:
s - The String object to be appended.


insert

public void insert(char c,
                   int index)
Insert a character immediately before a particular character.

Parameters:
c - The character to be inserted.

index - Where to insert c. The character currently at index will me moved to the right.


insert

public void insert(Str s,
                   int index)
Insert a Str object immediately before a particular character.

Parameters:
s - The Str object to be inserted.

index - Where to insert s. The character currently at index will me moved to the right.


insert

public void insert(String s,
                   int index)
Insert a String object immediately before a particular character.

Parameters:
s - The String object to be inserted.

index - Where to insert s. The character currently at index will me moved to the right.


delete

public void delete(int index,
                   int howMany)
Remove characters from your string.

Parameters:
index - Referencing the first character to be removed.

howMany - The number of characters to remove.


deleteFirst

public void deleteFirst(int howMany)
Remove characters from the beginning of your string.

Parameters:
howMany - The number of characters to remove.


deleteFirst

public void deleteFirst()
Remove first character from the beginning of your string.


deleteLast

public void deleteLast(int howMany)
Remove characters from the end of your string.

Parameters:
howMany - The number of characters to remove.


deleteLast

public void deleteLast()
Remove the last character from the end of your string.


push

public void push(char c)
If you wish to treat your string like a stack, you can push and pop characters.

Parameters:
c - The character that will be appended to the end of your string.


pop

public char pop()
If you wish to treat your string like a stack, you can push and pop characters.

Remember the old assembly programming pearl: May all your pushes be popped.

Returns:
The last character in your string. If there are no more characters in the string, a null character is returned.


startsWith

public boolean startsWith(String s)
Test to see if your string begins with a specific sequence of characters.

This test is much faster than the equivalent in the regular expression library. And is also much faster than doing a substring comparison.

This test is case sensitive.

Parameters:
s - A String object representing the first few characters being tested for.

Returns:
True if s matches the beginning of your string exactly.


indexOf

public int indexOf(char c,
                   int startPos)
Find the position within your string of a particular character.

This method is case sensitive.

Parameters:
c - The character to search for.

startPos - The character position in your string to start looking for c.

Returns:
The position of the character that matches c where 0 is the first character of the string. -1 is returned if a matching character could not be found.


indexOfIgnoreCase

public int indexOfIgnoreCase(char c,
                             int startPos)
Find the position within your string of a particular character, ignoring case.

This method is not case sensitive.

Parameters:
c - The character to search for.

startPos - The character position in your string to start looking for c.

Returns:
The position of the character that matches c where 0 is the first character of the string. -1 is returned if a matching character could not be found.


indexOf

public int indexOf(String s,
                   int startPos)
Find the position within your string of a particular sequence of characters.

This method is case sensitive.

Parameters:
s - A String object representing the character sequence to search for.

startPos - The character position in your string to start looking for s.

Returns:
-1 is returned if a match could not be found. Otherwise the position of the first character of the match is returned.


indexOfIgnoreCase

public int indexOfIgnoreCase(String s,
                             int startPos)
Find the position within your string of a particular sequence of characters, ignoring the case.

This method is not case sensitive.

Parameters:
s - A String object representing the character sequence to search for.

startPos - The character position in your string to start looking for s.

Returns:
-1 is returned if a match could not be found. Otherwise the position of the first character of the match is returned.


indexOf

public int indexOf(char c)
Find the position within your string of a particular character.

This method is case sensitive. Searching begins with the first character in your string.

Parameters:
c - The character to search for.

Returns:
The position of the character that matches c. -1 is returned if a matching character could not be found.


indexOf

public int indexOf(String s)
Find the position within your string of a particular sequence of characters.

This method is case sensitive. Searching begins with the first character in your string.

Parameters:
s - A String object representing the character sequence to search for.

Returns:
-1 is returned if a match could not be found. Otherwise the position of the first character of the match is returned.


indexOfIgnoreCase

public int indexOfIgnoreCase(char c)
Find the position within your string of a particular character, ignoring case.

This method is not case sensitive. Searching begins with the first character in your string.

Parameters:
c - The character to search for.

Returns:
The position of the character that matches c. -1 is returned if a matching character could not be found.


indexOfIgnoreCase

public int indexOfIgnoreCase(String s)
Find the position within your string of a particular sequence of characters, ignoring case.

This method is not case sensitive. Searching begins with the first character in your string.

Parameters:
s - A String object representing the character sequence to search for.

Returns:
-1 is returned if a match could not be found. Otherwise the position of the first character of the match is returned.


lastIndexOf

public int lastIndexOf(char c)
Returns the last index of this where the given char is found starting from the end of the String. Returns -1 if the character is not found. Results are zero based meaning the first character is equal to 0.

Example (assume this is "abc"):
lastIndexOf('c') == 2

Parameters:
c - a character
Returns:
position of the last

endsWith

public boolean endsWith(String s)
Does the string object end with this bit of text.

Parameters:
s - the suffix you are looking for.

Returns:
character at the end of the String s

firstDigit

public int firstDigit()
Returns the index of the first digit, or returns -1 if there are no digits.

Returns:
first numeric character (digit)

replace

public void replace(char c1,
                    char c2)
Replace all instances of one character with another character.

All occurances are replaced.

Searching for the "next instance" of character will begin immediately after the last replacement so that there is no chance of an infinite loop.

Parameters:
c1 - The character to search for.

c2 - The character that is to replace c1.


replace

public void replace(char c,
                    String s)
Replace all instances of one character with a String object.

All occurances are replaced.

Searching for the "next instance" of character will begin immediately after the last replacement so that there is no chance of an infinite loop.

Parameters:
c - The character to search for.

s - The String object that is to replace c.


replace

public void replace(String s,
                    char c)
Search for a particular character sequence and replace it with one character.

All occurances are replaced.

Searching for the "next instance" of a character sequence will begin immediately after the last replacement so that there is no chance of an infinite loop.

Parameters:
s - A String object representing a character sequence to search for.

c - The character that is to replace s.


replace

public void replace(String s1,
                    String s2)
Search for a particular character sequence and replace it with a different character sequence.

All occurances are replaced.

Searching for the "next instance" of a character sequence will begin immediately after the last replacement so that there is no chance of an infinite loop.

Parameters:
s1 - A String object representing a character sequence to search for.

s2 - A String object representing a character sequence that is to replace s1.


removeDoubleSpaces

public void removeDoubleSpaces()
Eliminate all occurances of two more space in a row.

When this method is done, there will not be an occurance of two spaces in a row. Anywhere that there was two or more spaces, there is now only one space.


charCount

public int charCount(char c)
Count how many times a particular character occurs within your string.

As dumb as this sounds, the method does end up getting used a lot.

Parameters:
c - The character to look for.

Returns:
The number of times the character occured in this string.


trimLead

public void trimLead()
Trims all leading spaces, no trailing spaces.


trimTrail

public void trimTrail()
Trims all trailing spaces, no leading spaces.


trim

public void trim()
Trims all leading spaces and all trailing spaces.


trimLeadWhitespace

public void trimLeadWhitespace()
Trims all leading spaces, newlines, returns and tabs.


trimTrailWhitespace

public void trimTrailWhitespace()
Trims all trailing spaces, newlines, returns and tabs.


trimWhitespace

public void trimWhitespace()
Trims all leading spaces, newlines, returns and tabs and all trailing spaces, newlines, returns and tabs.


trimTrailTo

public void trimTrailTo(char c)
Trims all characters from end of the string until a particular character is encountered.

The character being searched for is also trimmed.

Parameters:
c - The character to search for.


extractWord

public Str extractWord()
Extract and return the first word.

Space delimited (all double spaces are removed).

Returns:
A Str object representing the first word found in the string. No spaces are returned. If there are no words left, an empty Str object is returned.


hashCode

public int hashCode()
Return this as a hashcode

Overrides:
hashCode in class Object
Returns:
hashcode version of this

equals

public boolean equals(Object obj)
Compares equality with the object given

Overrides:
equals in class Object
Parameters:
obj - object to compare to
Returns:
true if equal otherwise false

toString

public String toString()
Convert this Str object to a String object.

Overrides:
toString in class Object
Returns:
A String object with an exact copy of your string.


forceNumeric

public void forceNumeric()
Force string to be the first number found.

Everything that is not a number, period or hyphen is converted to a space. The resulting string is the first word extracted.


toInt

public int toInt()
Try to convert this string to an integer value.

Returns:
Zero if the value is supposed to be zero or if there were any problems.


toLong

public long toLong()
Try to convert this string to a long value.

Returns:
Zero if the value is supposed to be zero or if there were any problems.


toDouble

public double toDouble()
Try to convert this string to a double value.

Returns:
Zero if the value is supposed to be zero or if there were any problems.


leftSpaceCount

public int leftSpaceCount()
Report how many leading spaces there are.

Returns:
the number of leading spaces in your string.


rightSpaceCount

public int rightSpaceCount()
Report how many trailing spaces there are.

Returns:
the number of trailing spaces in your string.


left

public void left(int newLen)
Force the length of the string and keep text to the left.

If the new length is longer, spaces will be added to the right.

If the new length is shorter, characters are chopped off from the right.

Useful for formatting text to be left justified.

Parameters:
newLen - The desired new length.


right

public void right(int newLen)
Force the length of the string and keep text to the right.

If the new length is longer, spaces will be added to the left.

If the new length is shorter, characters are chopped off from the right (not the left).

Useful for formatting text to be right justified.

Parameters:
newLen - The desired new length.


center

public void center(int newLen)
Try to center the text in a pad of spaces.

First, all leading and trailing spaces are removed.

If the new length is longer, spaces will be added to the left and right.

If the new length is shorter, the string is unchanged. In this case, the resulting string is longer than the new length!

Useful for formatting text to be centered.

Parameters:
newLen - The desired new length.


toUpper

public void toUpper()
All characters are forced to upper case.


toUpper

public void toUpper(int index)
Char at index is forced to upper case.

Parameters:
index - position within this to change to upper case

toVector

public Vector toVector(char delimiter)
Method toVector converts a delimited representation into a vector of separate values.

Parameters:
delimiter - the delimiting character to use
Returns:
the resulting java.util.Vector object

toVector

public static Vector toVector(String s)
Convenience method variant of toVector that converts a comma delimited String into a vector of separate values.

Parameters:
s - a String
Returns:
the resulting java.util.Vector object

toVector

public static Vector toVector(String s,
                              char delimiter)
Method toVector converts a delimited String into a vector of separate values.

Parameters:
s - a String
delimiter - the delimiting character to use
Returns:
the resulting java.util.Vector object

isUpper

public boolean isUpper(int index)
Is char at index upper case?

Parameters:
index - position within this to test
Returns:
true if the character at position index was upper case, otherwise false

toLower

public void toLower()
All characters are forced to lower case.


toLower

public void toLower(int index)
Char at index is forced to lower case.

Parameters:
index - position within this to force to lowercase

isLower

public boolean isLower(int index)
Is char at index lower case?

Parameters:
index - position within this to test
Returns:
true if the character is lowercase otherwise false

trailingDigits

public int trailingDigits()
Count the number of trailing digits.

Only values '0' through '9' are considered.

Returns:
number of trailing digits found in this

countRange

public int countRange(char low,
                      char high)
Determines the number of digits that occur within the given range within this.

Pass in 'a' and 'c' with the string "abcdefg" and the result will be 3.

Parameters:
low - this char is included in the range
high - this char is included in the range
Returns:
the number of characters found within the range

countDigits

public int countDigits()
Counts the number of digits in this.

Returns:
the number of digits found in the string.

reverse

public void reverse()
Reverse the order of all the characters.

Designed to behave the same way as StringBuffer.reverse().


moneyStr

public static String moneyStr(double d)
Converts a double to a string with two decimal places.

   Examples:   In       Out
 

0.0 "0.00" 1.9999 "2.00" 222.2222 "222.22"

Parameters:
d - The double value.

Returns:
A String object with the formated number.


formatDouble

public static String formatDouble(double d,
                                  int decimalPlaces)
Converts a double to a string with a specified number of decimal places.

Parameters:
d - The double value.

decimalPlaces - The number of decimal places needed.

Returns:
A String object with the formated number.


commaStr

public static String commaStr(double val)
Converts a double to a string with commas inserted for thousands, millions, etc.

Fractional values are ignored.

Parameters:
val - The double value.

Returns:
A String object with the formated number.


atoi

public static int atoi(String s)
Like the ANSI c function atoi().

Parameters:
s - The string that begins with a number.

Returns:
The integer that was extracted or 0 if any problems were encountered.


atoi

public static int atoi(char c)
Sort of like the ANSI c function atoi().

Instead of passing in a string, pass in a character.

Parameters:
c - The char containing a single digit.

Returns:
The integer that was extracted ( 0 through 9 ) or 0 if any problems were encountered.


atod

public static double atod(String s)
Like the ANSI c function atod().

Parameters:
s - The string that begins with a number.

Returns:
The double that was extracted or 0.0 if any problems were encountered.


verboseMoney

public static Str verboseMoney(double x)
Convert a double to English ( 12.01 -> "twelve and 01/100" ).

   Examples:   In          Out
 

0.0 "zero and 00/100" 23.23 "twenty-three and 23/100" 12345678.90 "twelve million three hundred forty-five thousand six hundred seventy-eight and 90/100"

Parameters:
x - The double to convert.

Returns:
The Str object containing the results.


nowStr

public static String nowStr()
Get the current local date and time. For more elaborate date string manipulation use EDate.

Returns:
A String object with the current local date and time.

See Also:
EDate

stringOf

public static Str stringOf(int quan,
                           char c)
Create a Str object containing nothing but a quantity of one character.

Example: calling stringOf( 20 , '-' ) returns a string of 20 hyphens.

Parameters:
quan - The desired string length.

c - The desired character.

Returns:
The new Str object.


spaces

public static Str spaces(int quan)
Create a Str object containing nothing but a quantity of spaces.

Parameters:
quan - The number of spaces desired.

Returns:
series of spaces

substring

public static String substring(String s,
                               int index,
                               int length)
Same as substring but uses mixed case nomenclature.

Parameters:
s - A String object that you want to extract a sub-string from.

index - Where the sub-string begins.

length - How long you want your sub-string to be.

Returns:
portion of the given String from index to length

subString

public static String subString(String s,
                               int index,
                               int length)
An improved String substring method that returns a portion of the given String.

Performs the same basic function as the String variant but is more robust and less likely to throw exceptions.

Parameters:
s - A String object that you want to extract a sub-string from.

index - Where the sub-string begins.

length - How long you want your sub-string to be.

Returns:
portion of the given String from index to length

before

public static String before(String s,
                            int index)
Get all of the substring that occurs before a particular character.

Parameters:
s - The String object to extract the substring from.

index - The character that marks the end of the substring. This character is not included in the substring.

Returns:
A String object containing the substring.


through

public static String through(String s,
                             int index)
Get all of the substring that occurs through a particular character.

Parameters:
s - The String object to extract the substring from.

index - The character that marks the end of the substring. This character is included in the substring.

Returns:
A String object containing the substring.


after

public static String after(String s,
                           int index)
Get all of the substring that occurs after a particular character.

Parameters:
s - The String object to extract the substring from.

index - The character that marks the beginning of the substring. This character is not included in the substring.

Returns:
A String object containing the substring.


from

public static String from(String s,
                          int index)
Get all of the substring that occurs from a particular character to the end of the string.

Parameters:
s - The String object to extract the substring from.

index - The character that marks the beginning of the substring. This character is included in the substring.

Returns:
A String object containing the substring.


left

public static String left(String s,
                          int newLen)
Force the length of the string and keep text to the left.

If the new length is longer, spaces will be added to the right.

If the new length is shorter, characters are chopped off from the right.

Useful for formatting text to be left justified.

Parameters:
s - The String object to process.

newLen - The desired new length.

Returns:
The new string object.


right

public static String right(String s,
                           int newLen)
Force the length of the string and keep text to the right.

If the new length is longer, spaces will be added to the left.

If the new length is shorter, characters are chopped off from the right (not the left).

Useful for formatting text to be right justified.

Parameters:
s - The String object to process.

newLen - The desired new length.

Returns:
The new string object.


center

public static String center(String s,
                            int newLen)
Try to center the text in a pad of spaces.

First, all leading and trailing spaces are removed.

If the new length is longer, spaces will be added to the left and right.

If the new length is shorter, the string is unchanged. In this case, the resulting string is longer than the new length!

Useful for formatting text to be centered.

Parameters:
s - The String object to process.

newLen - The desired new length.

Returns:
The new string object.


trimWhitespace

public static String trimWhitespace(String s)
Removes all whitespace from the given String. Different from String.trim(String) in that it will not throw an exception if the entire String is trimmed (not useable) and can return null.

Parameters:
s - a String
Returns:
s with all whitespace removed

trailingDigits

public static int trailingDigits(String s)
Count the number of trailing digits in the given String.

Only values '0' through '9' are considered.

Parameters:
s - a String
Returns:
number of trailing digits in s

usable

public static boolean usable(String s)
Determines if the given String is useable. A String is considered useable if it contains at least one non-whitespace character.

Parameters:
s - a String
Returns:
true if the string contains at least one non-whitespace character.

toInt

public static int toInt(String s)
Try to convert a string to an integer value.

Parameters:
s - a String
Returns:
Zero if the value is supposed to be zero or if there were any problems.


toLong

public static long toLong(String s)
Try to convert a string to a long value.

Parameters:
s - a String
Returns:
Zero if the value is supposed to be zero or if there were any problems.


toDouble

public static double toDouble(String s)
Try to convert a string to a double value.

Parameters:
s - a String
Returns:
Zero if the value is supposed to be zero or if there were any problems.


toTimestamp

public static Timestamp toTimestamp(String s)
Try to convert a string to a Timestamp object.

Parameters:
s - a String
Returns:
null if null is passed in or were any format problems.


toBoolean

public static boolean toBoolean(String s)
Try to convert a string to a boolean value.

Parameters:
s - a String
Returns:
True if the first char of the string is 'T', 't', 'Y' or 'y'. Anything else (including null or empty string) returns false.


trim

public static String trim(String s)
Return a string that is either null or has at least one character.

Note that this is a bit different than String.trim() or the instance method of this class. Those methods will never return a null.

This method is useful if your goal is to reduce the number of objects for serialization.

The inverse of this method is Str.normalize()

Parameters:
s - a String
Returns:
s or null if s contained no useable characters
See Also:
usable(String)

normalize

public static String normalize(Object s)
Return a string that is not null.

If s is null, return "". Else return s.

This method is useful if you could be passed a null string and you want to treat a null as an empty string.

Frequently used when showing data that has been serialized and the empty strings were converted to null to save space.

Parameters:
s - an Object
Returns:
a String representation of the object

equal

public static boolean equal(String s1,
                            String s2)
Uses String.equals(), but will consider that either or both strings might be null.

Parameters:
s1 - a String
s2 - a String
Returns:
true if the contents of both strings are the same or if both strings are null.

equal

public static boolean equal(String[] s1,
                            String[] s2)
Uses String.equals(), but will consider that either or both arrays/strings might be null.

Parameters:
s1 - a String
s2 - a String
Returns:
true if the contents of both arrays are the same or if both arrays are null.

toStringArray

public static String[] toStringArray(int[] values)
Converts a series of integers to a series of corresponding Strings.

Parameters:
values - array of integers
Returns:
array of equivelant Strings

toIntArray

public static int[] toIntArray(String[] values)
The inverse of toStringArray, builds a array of integers from an array of Strings.

Parameters:
values - array of Strings
Returns:
array of integers

getChar

public static char getChar(String s,
                           int index)
Just like String.charAt() except for null strings or for strings that are too short, an exception will not be thrown and instead, a null char will be returned.

Parameters:
s - String to search
index - character position
Returns:
character or null

StringToHex

public static String StringToHex(String s)
                          throws IllegalArgumentException
Method StringToHex converts a String object to a Hexidecimal version of the String object. The resulting Hexidecimal version is itself a String object.

For example: "My String" = "4d7920537472696e67"

If any character inside the String is outside of the printable boundary for Unicode characters (is a Control character), an illegal argument exception will be thrown.

Parameters:
s - the String object to convert
Returns:
the Hexidecimal representation of the String s
Throws:
IllegalArgumentException - thrown if the String contains Control characters
Since:
Text 1.0
See Also:
HexToString(String), HexToString(String,boolean)

StringToHex

public String StringToHex()
                   throws IllegalArgumentException
Method StringToHex the non-static version of StringToHex()

Returns:
the hex representation of this String
Throws:
IllegalArgumentException

StringToHex

public static String StringToHex(String s,
                                 boolean pad)
Method StringToHex converts a String object to a Hexidecimal version of the String object. The resulting Hexidecimal version is itself a String object. The pad allows the Hexidecimal representation to take on two forms, one narrow, the other wide. To decompose the wide version you must use the HexToString(String, boolean) version with pad equal to true as well. For the narrow version, the short form of HexToString(String) will also work.

For example: "My String" = "4d7920537472696e67" with pad = false "My String" = "4d 79 20 53 74 72 69 6e 67" with pad = true

If any character inside the String is outside of the printable boundary for Unicode characters (is a Control character), an illegal argument exception will be thrown.

Parameters:
s - the String object to convert
pad - a boolean parameter to indicate if the Hexidecimal String returned should separate the Hexidecimal values for each character byte with a space
Returns:
the Hexidecimal representation of the String s
Since:
Text 1.0
See Also:
HexToString(String,boolean)

StringToHex

public String StringToHex(boolean pad)
Method StringToHex non-static version of StringToHex

Parameters:
pad - true or false whether the result should be padded or not
Returns:
the Hex representation of the this String

HexToString

public static String HexToString(String hex)
Method HexToString converts a Hexidecimal string to an ASCII string. Effectively the reverse of StringToHex. There are two versions of this method, one uses narrow notation and the other may use either wide or narrow notation. Narrow notation is 2-digit hexidecimal strings of even byte length represented as "4d7920537472696e67". Wide notation is represented as "4d 79 20 53 74 72 69 6e 67".

This version uses only the narrow notation (the default).

Parameters:
hex - the Hexidecimal String to convert to an ASCII String object
Returns:
the converted String object
Since:
Text 1.0
See Also:
StringToHex(String), StringToHex(String,boolean)

HexToString

public String HexToString()
Method HexToString non-static version of HexToString

Returns:
String from this if this is currently hex

HexToString

public static String HexToString(String hex,
                                 boolean pad)
Method HexToString converts a Hexidecimal string to an ASCII string. Effectively the reverse of StringToHex. There are two versions of this method, one uses narrow notation and the other may use either wide or narrow notation. Narrow notation is 2-digit hexidecimal strings of even byte length represented as "4d7920537472696e67". Wide notation is represented as "4d 79 20 53 74 72 69 6e 67".

This version can convert either wide or narrow notation Hexidecimal strings. Use true to specify a wide (padded) version or false to indicate that the string is narrow (not padded).

Parameters:
hex - the Hexidecimal String to convert to an ASCII String object
pad - indicates that the Hexidecimal String is padded (true) or in not padded (false) meaning that it does or does not have a space between the Hex byte values.
Returns:
the converted String object
See Also:
StringToHex(String), StringToHex(String,boolean)

HexToString

public String HexToString(boolean pad)
Method HexToString non-static version of HexToSring.

Parameters:
pad - true if the resulting hex should be padded
Returns:
padded hex string

Chr

public static char Chr(int i)
                throws NumberFormatException
Method Chr returns the ASCII character with is the binary equivelant to the integer given. The integer value must be one that represents a printable non-Control character in the range of 32 through 126. This functionally the inverse of the Ascii method.

Parameters:
i - the integer value of the character
Returns:
the character representation of the integer
Throws:
NumberFormatException - thrown if the integer i is less than 32 or greater than 255
Since:
Text 1.0
See Also:
Ascii(char), CharToInt(char), IntToChar(int)

IntToChar

public static char IntToChar(int i)
Method IntToChar returns the ASCII character with is the binary equivelant to the integer given. The integer value must be one that represents a printable non-Control character in the range of 32 through 126. This functionally the inverse of the Ascii and CharToInt(char) method. It is equivilent to the Chr(int) method.

Parameters:
i - the integer value of the character
Returns:
the character representation of the integer
Since:
Text 1.0
See Also:
Ascii(char), Chr(int), CharToInt(char)

Ascii

public static int Ascii(char c)
                 throws IllegalArgumentException
Method Ascii returns the decimal representation of the character given. The character given must be a non-Control (printable) character or an IllegalArgumentException will be thrown. This is functionally the inverse of the Chr method.

Parameters:
c - the character to convert
Returns:
the integer representation of the ASCII character
Throws:
IllegalArgumentException - thrown if the character is a non-printable ISO Control character
See Also:
Chr(int), IntToChar(int), CharToInt(char)

CharToInt

public static int CharToInt(char c)
Method CharToInt returns the decimal representation of the character given. The character given must be a non-Control (printable) character or an IllegalArgumentException will be thrown. This is functionally the inverse of the Chr method or IntToChar(int) method. It is also the equivelant of the Ascii(char) method.

Parameters:
c - the character to convert
Returns:
the integer representation of the ASCII character
See Also:
Chr(int), IntToChar(int), Ascii(char)

CharToHex

public static String CharToHex(char c)
                        throws IllegalArgumentException
Method CharToHex converts a character to a hexidecimal String that represents the characters ASCII integer representation. Similar to the Ascii method in that the character is converted to it's ASCII representative number. The difference being that Ascii returns the value as an integer whereas CharToHex returns the value as a hexidecimal number.

Parameters:
c - the character to convert
Returns:
a 2-byte hexidecimal String representing the ASCII decimal code for the given character
Throws:
IllegalArgumentException - thrown when the character given is a non-printable ISO Control character
See Also:
HexToChar(String)

HexToChar

public static char HexToChar(String hex)
                      throws IllegalArgumentException
Method HexToChar converts a 2-byte hexidecimal String to the ASCII character that it represents. If the String is longer than 2 bytes or any character is not a legitimate hexidecimal character (0-9, a[A]-f[F]) then an exception is thrown. If the integer value of the string is less than 32 or greater than 255 then a NumberFormatException is thrown because the character would effectively be a non-printable ISO Control character.

Parameters:
hex - the 2-byte hexidecimal String to convert
Returns:
the character which represents the hexidecimal number given
Throws:
IllegalArgumentException - thrown if the string is longer than 2-bytes or contains non-hexidecimal characters
NumberFormatException - thrown when the string contains the equivelant of ISO Control characters
See Also:
CharToHex(char)

HexToInt

public static int HexToInt(String hex)
Method HexToInt converts an hexidecimal String to a integer. Unlike the character conversions, this method will convert hexidecimal strings of lengths longer than two bytes.

For example: 38 = "26" 43 = "2b"

Parameters:
hex - the hexidecimal String to convert
Returns:
the integer value of the given hexidecimal String
See Also:
IntToHex(int)

IntToHex

public static String IntToHex(int i)
Method IntToHex converts an integer to a hexidecimal String. Unlike many of the other conversion methods in this package, there is no restriction to limit the integer to numbers greater than 126 or less than 32.

For example: "4bc2" = 19394

Parameters:
i - the integer to convert
Returns:
the hexidecimal String equivelant of the integer given.
See Also:
HexToInt(String)

spacer

public String spacer()
Establishes and converts the spacing character to a string.

Returns:
The character c coerced to a String element.

setSpacer

public void setSpacer(char c)
Set the spacer character property

Parameters:
c - character to set the spacer to

setCr

public void setCr(String c)
Sets the carriage return property to the given String value. This property is initially set to the default for the platform where the class is running. In some situations this may not be appropriate, such as when running programs from a UNIX server with output destined for a Windows client.

Parameters:
c - a String to use as the carriage return.

getCr

public String getCr()
Returns the current carriage return value.

Returns:
carriage return value

spacer

public static String spacer(char c)
Returns the a char spacer as a String

Parameters:
c - char for spacing
Returns:
String for spacing

pad

public String pad(int l)
Returns a padded string with a length of int len comprised of char c.

Parameters:
l - The requested length of the resulting string.
Returns:
The padded string using character c.
See Also:
lpad(int, char), rpad(int, char)

pad

public static String pad(char c,
                         int l)
Creates a string of characters to a given length for use in padding.

Parameters:
c - a character
l - length of the pad to create
Returns:
String of characters of given length
See Also:
rpad(int,char), rpad(String,int,char), lpad(int,char), lpad(String,int,char)

rpad

public String rpad(int l,
                   char c)
Right pads current Str with Char c out to length Int len. If length s >= len, then s is returned.
Examples:
rpad("foo", 6, 'r') = "foorrr"
rpad("foo", 3, 'r') = "foo"

Parameters:
l - The length you want the final string to be.
c - The character to use for padding String s.
Returns:
The complete padded string.
See Also:
pad(int)

rpad

public static String rpad(String s,
                          int len,
                          char c)
Right pads String s with Char c out to length Int len. If length s >= len, then s is returned.
Examples:
rpad("foo", 6, 'r') = "foorrr"
rpad("foo", 3, 'r') = "foo"

Parameters:
s - String you wish to pad.
len - The length you want the final string to be.
c - The character to use for padding String s.
Returns:
The complete padded string.
See Also:
pad(int)

lpad

public String lpad(int l,
                   char c)
Left pads this Str with Char c out to length Int l. If length s >= l, then s is returned.
Examples:
rpad("foo", 6, 'r') = "rrrfoo"
rpad("foo", 3, 'r') = "foo"

Parameters:
l - The length you want the final string to be expressed as total character length.
c - The character to use for padding String s.
Returns:
The complete padded string.
See Also:
pad(int)

getDefaultWrapPoint

public int getDefaultWrapPoint()
Returns the default wrap point property

Returns:
position where text wraps by default

setDefaultWrapPoint

public void setDefaultWrapPoint(int n)
Sets the default wrap point property

Parameters:
n - wrap point position

lpad

public static String lpad(String s,
                          int len,
                          char c)
Left pads String s with Char c out to length Int len. If length s >= len, then s is returned.
Examples:
rpad("foo", 6, 'r') = "rrrfoo"
rpad("foo", 3, 'r') = "foo"

Parameters:
s - String you wish to pad.
len - The length you want the final string to be expressed as total character length.
c - The character to use for padding String s.
Returns:
The complete padded string.
See Also:
pad(int)

wrap

public String wrap()
Wraps String s at position 80 using line terminator ascii 13 + ascii 11.

Examples:
wrap("1234567890...100") = "1234567890...80[\\r\\n]81...100"

Returns:
The wrapped string.

wrap

public static String wrap(String s)
Wraps String s at position 80 using line terminator ascii 13 + ascii 11.

Examples:
wrap("1234567890...100") = "1234567890...80[\\r\\n]81...100"

Parameters:
s - String you wish to wrap.
Returns:
The wrapped string.

wrap

public String wrap(int l)
Wraps String s at break position int len using line terminator ascii 13 + ascii 11. If length s <= len, then s is returned.
Examples:
wrap("foobar", 3) = "rrr[\\r\\n]foo"

Parameters:
l - The position to wrap the line at (default 80).
Returns:
The wrapped string.

wrap

public static String wrap(String s,
                          int len)
Wraps String s at break position int len using line terminator ascii 13 + ascii 11. If length s <= len, then s is returned.
Examples:
wrap("foobar", 3) = "rrr[\\r\\n]foo"

Parameters:
s - String you wish to wrap.
len - The position to wrap the line at (default 80).
Returns:
The wrapped string.

wrap

public String wrap(int l,
                   String c)
Wraps String s at wrap position int len using line terminator String cr. If length s <= l, then s is returned.
Examples:
wrap("foobar", 3, "\\r\\n") = "rrr[\r\n]foo"

Parameters:
l - The position to break at (default 80).
c - The terminating string to use (default ascii 13 + ascii 11 - cr + lf).
Returns:
The wrapped string.

wrap

public static String wrap(String s,
                          int l,
                          String c)
Wraps String s at wrap position int len using line terminator String cr. If length s <= len, then s is returned.
Examples:
wrap("foobar", 3, "\\r\\n") = "rrr[\r\n]foo"

Parameters:
s - String you wish to wrap.
l - The position to break at (default 80).
c - The terminating string to use (default ascii 13 + ascii 11 - cr + lf).
Returns:
The wrapped string.

wrap

public String wrap(int l,
                   String c,
                   int indentAmount,
                   char indentChar)
Wraps String s at position int len using line terminator String cr with indent character indentChar indented to indentAmount. If length s <= pos, then s is returned.
Examples:
wrap("foobar", 3, "\\r\\n", 1) = " rrr[\r\n] foo"

Parameters:
l - The position to wrap at (default 80).
c - The terminating string to use (default ascii 13 + ascii 11 - cr + lf).
indentAmount - The amount to indent the returned string
indentChar - The character to use for indentation
Returns:
The wrapped string.

wrap

public static String wrap(String s,
                          int l,
                          String c,
                          int indentAmount,
                          char indentChar)
Wraps String s at position int len using line terminator String cr with indent character indentChar indented to indentAmount. If length s <= pos, then s is returned.
Examples:
wrap("foobar", 3, "\\r\\n", 1) = " rrr[\r\n] foo"

Parameters:
s - String you wish to wrap.
l - The position to wrap at (default 80).
c - The terminating string to use (default ascii 13 + ascii 11 - cr + lf).
indentAmount - The amount to indent the returned string
indentChar - The character to use for indentation
Returns:
The wrapped string.

indent

public String indent(int indentAmount,
                     char indentChar)
Indents a string s using character indentChar by int len

Parameters:
indentAmount - TThe amount to indent the returned string.
indentChar - The character to use for indentation
Returns:
The indented string.

indent

public static String indent(String s,
                            int indentAmount,
                            char indentChar)
Indents a string s using character indentChar by int len

Parameters:
s - String you wish to indent.
indentAmount - TThe amount to indent the returned string.
indentChar - The character to use for indentation
Returns:
The indented string.

labelString

public static String labelString(String s,
                                 char labelChar,
                                 int wrapWidth,
                                 boolean encase)
Generates a centered 1 or 3 line label for text outputs. The string is centered within wrapWidth using an equal spacing of labelChar and blank space. If encase is true, then an encasing line is included above and below the string result.

If the length of s is within 4 characters of wrapwidth, the labelChar is ignored. if the length of s meets or exceeds wrapWidth then s is returned.

Examples:
s="Test"
labelChar='-'
wrapWidth= 20
encase=true
01234567890123456789 <- wrap ruler (shown for example)
--------------------
----    Test    ----
--------------------


s="Test"
labelChar='-'
wrapWidth= 20
encase=false
01234567890123456789 <- wrap ruler (shown for example)
----    Test    ----

Parameters:
s - String to turn into a label
labelChar - the character to use for the label graphic
wrapWidth - the range at which the label is centered
encase - optional flag to determine if the result is enclosed with label charaters on pre and post lines.
Returns:
String label padded or trimmed and centered

MDi JLib
1.7.4

Copyright©2001-2007 MicroDeveloper, Inc. All Rights Reserved.