java.lang.Object
|
+--stec.lang.DString
public final class DString
Methods to manipulate delimited strings.
Methods
|
Method
|
Description
|
|
change
|
Changes the first occurence of the given string in the specified string.
|
|
count
|
Returns the number of times the given delimiter was found in the specified
string.
|
|
dcount
|
Returns the number of delimited strings.
|
|
extract
|
Returns the specified string.
|
|
pad
|
Returns a fixed string with the given value justified and padded with the
specified delimiter.
|
|
replace
|
Replaces all occurences of the given string in the specified string.
|
|
trim
|
Returns a string where all leading, trailing and redundant spaces have been
removed.
|
change
Changes the first occurence of the given string in the specified string.
Syntax
public final static String change(String string, String old, String new)
Parameters
|
string
|
the string to change.
|
|
old
|
the substring to change.
|
|
new
|
the substring to change to.
|
Returns
|
String
|
the resultant string.
|
Throws
Example
input = DString.change(input, "http://", "");
count
Returns the number of times the given delimiter was found in the specified
string.
Syntax
public final static int count(String string, String delimiter)
Parameters
|
string
|
the string to use.
|
|
delimiter
|
the delimiter to count.
|
Returns
|
int
|
the number of times that the given delimited was found in the specified
string.
|
Throws
Example
int numberSpaces = DString.count(input, " ");
dcount
Returns the number of delimited strings.
Syntax
public final static int dcount(String string, String delimiter)
Parameters
|
string
|
the string to use.
|
|
delimiter
|
the delimiter.
|
Returns
|
int
|
the number of delimited strings. 0 if the string is empty or 1 if the
delimited was not found and the string was not empty.
|
Throws
Example
int lines = DString.dcount(input, "\n");
extract
Returns the specified string.
Syntax
public final static String extract(String string, String delimiter, int index)
Parameters
|
string
|
the string to use.
|
|
delimiter
|
the delimiter.
|
|
index
|
the index of the string to return.
|
Returns
|
String
|
the string at the specified index. null is index exceeds number of
strings.
|
Throws
Example
String line = DString.extract(script, "\n", index);
pad
Returns a fixed string with the given value justified and padded with the
specified delimiter.
Syntax
public final static String pad(String string,
String delimiter,
int size,
char justification)
Parameters
|
string
|
the string to pad.
|
|
delimiter
|
the delimiter to pad with.
|
|
size
|
the padded string size.
|
|
justification
|
the justification, r for right and l for left.
|
Returns
|
String
|
the padded string,
|
Throws
Example
String output = DString.pad(input, " ", );
replace
Replaces all occurences of the given string in the specified string.
Syntax
public final static String replace(String string, String old, String new)
Parameters
|
string
|
the string to change.
|
|
old
|
the substring to replace.
|
|
new
|
the substring to change to.
|
Returns
|
String
|
the resultant string.
|
Throws
Example
System.out.println(DString.replace(message, "\n", " "));
trim
Returns a string where all leading, trailing and redundant spaces have been
removed.
Syntax
public final static String trim(String string)
Parameters
|
string
|
the string to trim.
|
Returns
|
String
|
the resultant string.
|
Throws
Example
String command = DString.trim(message);
|