|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object netP5.StringUtils
public class StringUtils
Method Summary | |
---|---|
static String |
arrayToString(String[] theArray)
|
static String |
arrayToString(String[] theArray,
int theStart,
int theEnd)
|
static String |
centerJustify(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 String |
duplicate(String source,
int copies)
Returns a String with the source String copied the specified number of times. |
static String[] |
explode(String source)
Splits a string into an array with a space as delimiter. |
static Vector |
explode(String[] source,
int[] lengths)
Splits every String in an array at the specified lengths. |
static String[] |
explode(String source,
int[] lengths)
Splits a string at the specified lengths and returns an array of Strings. |
static String[] |
explode(String s,
String delimiter)
Splits a string into an array with the specified delimiter. |
static float |
getFloat(String theString)
|
static int |
getInt(String theString)
|
static String |
getStackTrace(Throwable t)
Prints the stacktrace to a buffer and returns the buffer as a String. |
static String |
implode(Object[] elements)
Combines an array to a string, using a comma and a space as delimiter. |
static String |
implode(Object[] elements,
String delimiter)
Combines an array to a string, using the specified delimiter. |
static boolean |
isEmpty(String s)
Checks if a String is empty or null. |
static String |
left(String source,
String searchFor)
Returns the substring to the left of the specified substring in the specified String, starting from the left. |
static String |
leftBack(String source,
String searchFor)
Returns the substring to the left of the specified substring in the specified String, starting from the right. |
static String |
leftJustify(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 String |
middle(String source,
int startIndex,
int length)
Returns a substring of a String, starting from specified index and with specified length. |
static String |
middle(String source,
String start,
String end)
Returns the substring between two substrings. |
static String |
remove(String source,
char searchFor)
Removes all instances of a character in a String. |
static String |
remove(String source,
String searchFor)
Removes all instances of a substring in a String. |
static String |
remove(String source,
String[] searchFor)
Removes all instances of substrings in a String. |
static String |
removeDuplicates(String source,
String searchFor)
Removes duplicates of a substring in a String. |
static String |
replace(String source,
String[] searchFor,
String replaceWith)
Replaces several substrings in a string. |
static String |
replace(String source,
String searchFor,
String replaceWith)
Replaces substrings in a string. |
static String |
right(String source,
String searchFor)
Returns the substring to the right of the specified substring in the specified String, starting from the left. |
static String |
rightBack(String source,
String searchFor)
Returns the substring to the right of the specified substring in the specified String, starting from the right. |
static String |
rightJustify(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 String[] |
slice(int theNum,
String[] theStringArray)
|
static 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 String |
switchCase(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 String right(String source, String searchFor)
source
- the source String to search.searchFor
- the substring to search for in source.
public static String rightBack(String source, String searchFor)
source
- the source String to search.searchFor
- the substring to search for in source.
public static String left(String source, String searchFor)
source
- the source String to search.searchFor
- the substring to search for in source.
public static String leftBack(String source, String searchFor)
source
- the source String to search.searchFor
- the substring to search for in source.
public static String middle(String source, String start, 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 String middle(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 String replace(String source, String searchFor, 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 String replace(String source, String[] searchFor, 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 Vector explode(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 String[] explode(String source, int[] lengths)
source
- the String to split.
IndexOutOfBoundsException
- if any of the length´s are invalid.public static String[] explode(String source)
source
- the source String to explode.
public static String[] explode(String s, 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.
NullPointerException
- if s is null.public static String[] slice(int theNum, String[] theStringArray)
public static String implode(Object[] elements, String delimiter)
elements
- the array to combine to a single string.delimiter
- the delimiter to put between the combined elements.
public static String implode(Object[] elements)
elements
- the array to combine to a single string.
public static String remove(String source, char searchFor)
source
- the String to remove substring in.searchFor
- the character to remove.
public static String remove(String source, String searchFor)
source
- the String to remove substring in.searchFor
- the substring to remove.
public static String remove(String source, String[] searchFor)
source
- the String to remove substrings in.searchFor
- an array of substrings to remove from the source String.
public static String removeDuplicates(String source, 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 String getStackTrace(Throwable t) throws IOException
t
- the Throwable you wnat to generate a stacktrace for.
IOException
public static boolean isEmpty(String s)
s
- the String to test if it is empty or null.
public static String leftJustify(String source, int length)
source
- the String to justifylength
- the length of the resulting String
public static String rightJustify(String source, int length)
source
- the String to justifylength
- the length of the resulting String
public static String centerJustify(String source, int length)
source
- the String to justifylength
- the length of the resulting String
public static String spaces(int length)
length
- the number of spaces to return.
public static String duplicate(String source, int copies)
source
- the source String to copy.length
- the number of copies of source to return.
public static String switchCase(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(String theString)
public static float getFloat(String theString)
public static String arrayToString(String[] theArray)
public static String arrayToString(String[] theArray, int theStart, int theEnd)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |