java.lang.Object
|
+--stec.lang.DString
public 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.
|
find
|
Returns the occurence within the given delimited string where the specified
substring if found.
|
findIgnoreCase
|
Returns the occurence within the given delimited string where the specified
substring if found ignoring case.
|
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 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 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 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 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);
find
Returns the occurence within the given delimited string where the specified
substring was found.
Syntax
public static int find(String string,
String delimiter,
String substring)
public static int find(String string,
String delimiter,
int startingIndex,
String substring)
Parameters
string
|
the string to search.
|
delimiter
|
the delimiter.
|
substring
|
the string to find.
|
startingOffset
|
the starting index.
|
Returns
int
|
the occurence within the given delimited string where the specified substring
was found, -1 if not found.
|
Throws
Example
int index = DString.find(hosts, ",", host);
findIgnoreCase
Returns the occurence within the given delimited string where the specified
substring if found ignoring case.
Syntax
public static int findIgnoreCase(String string,
String delimiter,
String substring)
public static int findIgnoreCase(String string,
String delimiter,
int startingIndex,
String substring)
Parameters
string
|
the string to search.
|
delimiter
|
the delimiter.
|
substring
|
the string to find.
|
startingOffset
|
the starting index.
|
Returns
int
|
the occurence within the given delimited string where the specified substring
was found, -1 if not found.
|
Throws
Example
int index = DString.findIgnoreCase(hosts, ",", host);
pad
Returns a fixed string with the given value justified and padded with the
specified delimiter.
Syntax
public 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 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 static String trim(String string)
Parameters
string
|
the string to trim.
|
Returns
String
|
the resultant string.
|
Throws
Example
String command = DString.trim(message);
|