|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectnetP5.StringUtils
public class StringUtils
Method Summary | |
---|---|
static java.lang.String |
arrayToString(java.lang.String[] theArray)
|
static java.lang.String |
arrayToString(java.lang.String[] theArray,
int theStart,
int theEnd)
|
static java.lang.String |
centerJustify(java.lang.String source,
int length)
Creates a string of the given width with the given string left justified (padded by an appropriate number of spaces in front and after it). |
static java.lang.String |
duplicate(java.lang.String source,
int copies)
Returns a String with the source String copied the specified number of times. |
static java.lang.String[] |
explode(java.lang.String source)
Splits a string into an array with a space as delimiter. |
static java.util.Vector |
explode(java.lang.String[] source,
int[] lengths)
Splits every String in an array at the specified lengths. |
static java.lang.String[] |
explode(java.lang.String source,
int[] lengths)
Splits a string at the specified lengths and returns an array of Strings. |
static java.lang.String[] |
explode(java.lang.String s,
java.lang.String delimiter)
Splits a string into an array with the specified delimiter. |
static float |
getFloat(java.lang.String theString)
|
static int |
getInt(java.lang.String theString)
|
static java.lang.String |
getStackTrace(java.lang.Throwable t)
Prints the stacktrace to a buffer and returns the buffer as a String. |
static java.lang.String |
implode(java.lang.Object[] elements)
Combines an array to a string, using a comma and a space as delimiter. |
static java.lang.String |
implode(java.lang.Object[] elements,
java.lang.String delimiter)
Combines an array to a string, using the specified delimiter. |
static boolean |
isEmpty(java.lang.String s)
Checks if a String is empty or null. |
static java.lang.String |
left(java.lang.String source,
java.lang.String searchFor)
Returns the substring to the left of the specified substring in the specified String, starting from the left. |
static java.lang.String |
leftBack(java.lang.String source,
java.lang.String searchFor)
Returns the substring to the left of the specified substring in the specified String, starting from the right. |
static java.lang.String |
leftJustify(java.lang.String source,
int length)
Creates a string of the given width with the given string left justified (followed by an appropriate number of spaces). |
static java.lang.String |
middle(java.lang.String source,
int startIndex,
int length)
Returns a substring of a String, starting from specified index and with specified length. |
static java.lang.String |
middle(java.lang.String source,
java.lang.String start,
java.lang.String end)
Returns the substring between two substrings. |
static java.lang.String |
remove(java.lang.String source,
char searchFor)
Removes all instances of a character in a String. |
static java.lang.String |
remove(java.lang.String source,
java.lang.String searchFor)
Removes all instances of a substring in a String. |
static java.lang.String |
remove(java.lang.String source,
java.lang.String[] searchFor)
Removes all instances of substrings in a String. |
static java.lang.String |
removeDuplicates(java.lang.String source,
java.lang.String searchFor)
Removes duplicates of a substring in a String. |
static java.lang.String |
replace(java.lang.String source,
java.lang.String[] searchFor,
java.lang.String replaceWith)
Replaces several substrings in a string. |
static java.lang.String |
replace(java.lang.String source,
java.lang.String searchFor,
java.lang.String replaceWith)
Replaces substrings in a string. |
static java.lang.String |
right(java.lang.String source,
java.lang.String searchFor)
Returns the substring to the right of the specified substring in the specified String, starting from the left. |
static java.lang.String |
rightBack(java.lang.String source,
java.lang.String searchFor)
Returns the substring to the right of the specified substring in the specified String, starting from the right. |
static java.lang.String |
rightJustify(java.lang.String source,
int length)
Creates a string of the given width with the given string right justified (with an appropriate number of spaces before it). |
static java.lang.String[] |
slice(int theNum,
java.lang.String[] theStringArray)
|
static java.lang.String |
spaces(int length)
Returns a String with the specified number of spaces. |
static char |
switchCase(char source)
Switches the case of the supplied character. |
static java.lang.String |
switchCase(java.lang.String source)
Switches the case of the supplied String. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.lang.String right(java.lang.String source, java.lang.String searchFor)
source
- the source String to search.searchFor
- the substring to search for in source.
public static java.lang.String rightBack(java.lang.String source, java.lang.String searchFor)
source
- the source String to search.searchFor
- the substring to search for in source.
public static java.lang.String left(java.lang.String source, java.lang.String searchFor)
source
- the source String to search.searchFor
- the substring to search for in source.
public static java.lang.String leftBack(java.lang.String source, java.lang.String searchFor)
source
- the source String to search.searchFor
- the substring to search for in source.
public static java.lang.String middle(java.lang.String source, java.lang.String start, java.lang.String end)
source
- the String to search.start
- the String to the left to search for, from the left.end
- the String to the right to search for, from the right.public static java.lang.String middle(java.lang.String source, int startIndex, int length)
source
- the String to get a substring from.startIndex
- the index in the source String to get the substring from.length
- the length of the substring to return.public static java.lang.String replace(java.lang.String source, java.lang.String searchFor, java.lang.String replaceWith)
source
- the source String to replace substrings in.searchFor
- the string to search for.replaceWith
- the string to replace all found searchFor-substrings with.public static java.lang.String replace(java.lang.String source, java.lang.String[] searchFor, java.lang.String replaceWith)
source
- the source String to replace substrings in.searchFor
- the substrings to search for.replaceWith
- what to replace every searchFor with,public static java.util.Vector explode(java.lang.String[] source, int[] lengths)
String source[] = { "123a123b123c123d", "Bla1bla2bla3bla4bla5bla6bla7" };
int[] lengths = { 3, 1, 3, 1 };
Vector result = StringUtils.explode(source, lengths);
Object element = null;
String[] rowElements = null;
Enumeration enum = result.elements();
while (enum.hasMoreElements()) {
element = enum.nextElement();
if (element instanceof String[]) {
rowElements = (String[]) element;
for (int i = 0; i < rowElements.length; i++) {
System.out.println(rowElements[i]);
}
}
}
The result that will be output: 123 a 123 b
Bla 1 bla 2
public static java.lang.String[] explode(java.lang.String source, int[] lengths)
source
- the String to split.
java.lang.IndexOutOfBoundsException
- if any of the length´s are invalid.public static java.lang.String[] explode(java.lang.String source)
source
- the source String to explode.
public static java.lang.String[] explode(java.lang.String s, java.lang.String delimiter)
This method is meant to be similar to the split function in other programming languages but it does not use regular expressions. Rather the String is split on a single String literal. It is equivalent to the
s
- the String to explode.delimiter
- the delimiter where to split the string.
java.lang.NullPointerException
- if s is null.public static java.lang.String[] slice(int theNum, java.lang.String[] theStringArray)
public static java.lang.String implode(java.lang.Object[] elements, java.lang.String delimiter)
elements
- the array to combine to a single string.delimiter
- the delimiter to put between the combined elements.
public static java.lang.String implode(java.lang.Object[] elements)
elements
- the array to combine to a single string.
public static java.lang.String remove(java.lang.String source, char searchFor)
source
- the String to remove substring in.searchFor
- the character to remove.
public static java.lang.String remove(java.lang.String source, java.lang.String searchFor)
source
- the String to remove substring in.searchFor
- the substring to remove.
public static java.lang.String remove(java.lang.String source, java.lang.String[] searchFor)
source
- the String to remove substrings in.searchFor
- an array of substrings to remove from the source String.
public static java.lang.String removeDuplicates(java.lang.String source, java.lang.String searchFor)
source
- the String to remove duplicates in.searchFor
- the substring that can only occur one at a time, several can
exist in the source though.public static java.lang.String getStackTrace(java.lang.Throwable t) throws java.io.IOException
t
- the Throwable you wnat to generate a stacktrace for.
java.io.IOException
public static boolean isEmpty(java.lang.String s)
s
- the String to test if it is empty or null.
public static java.lang.String leftJustify(java.lang.String source, int length)
source
- the String to justifylength
- the length of the resulting String
public static java.lang.String rightJustify(java.lang.String source, int length)
source
- the String to justifylength
- the length of the resulting String
public static java.lang.String centerJustify(java.lang.String source, int length)
source
- the String to justifylength
- the length of the resulting String
public static java.lang.String spaces(int length)
length
- the number of spaces to return.
public static java.lang.String duplicate(java.lang.String source, int copies)
source
- the source String to copy.length
- the number of copies of source to return.
public static java.lang.String switchCase(java.lang.String source)
source
- the String to switch case of.
public static char switchCase(char source)
source
- the character to switch case of.
public static int getInt(java.lang.String theString)
public static float getFloat(java.lang.String theString)
public static java.lang.String arrayToString(java.lang.String[] theArray)
public static java.lang.String arrayToString(java.lang.String[] theArray, int theStart, int theEnd)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |