Class StringUtils
- Version:
- $Id: StringUtils.java 685685 2008-08-13 21:43:27Z nbubna $
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Check to see if all the string objects passed in are empty.static String
capitalizeFirstLetter
(String data) Capitalize the first letter but leave the rest as they are.static String
Chop i characters off the end of a string.static String
Chop i characters off the end of a string.static String
collapseNewlines
(String argStr) Remove/collapse multiple newline characters.static String
collapseSpaces
(String argStr) Remove/collapse multiple spaces.Concatenates a list of objects as a String.static String
fileContentsToString
(String file) Read the contents of a file and place them in a string object.static String
firstLetterCaps
(String data) Makes the first letter caps and the rest lowercase.static String
getPackageAsPath
(String pckge) Return a package name as a relative path namestatic final String
normalizePath
(String path) Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path after ".." and "." elements are resolved out.static String
Trim the string, but pass a null through.static String
removeAndHump
(String data) 'Camels Hump' replacement of underscores.static String
removeAndHump
(String data, String replaceThis) 'Camels Hump' replacement.static String
removeUnderScores
(String data) Deprecated.Use the org.apache.commons.util.StringUtils class instead.If state is true then return the trueString, else return the falseString.static String[]
Create a string array from a string separated by delimstatic final String
Returns the output of printStackTrace as a String.static StringBuffer
stringSubstitution
(String argStr, Hashtable vars) static StringBuffer
stringSubstitution
(String argStr, Map vars) Perform a series of substitutions.static final String
Replaces all instances of oldString with newString in line.static List
trimStrings
(List list) Trim all strings in a List.
-
Field Details
-
EOL
Line separator for the OS we are operating on.
-
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
concat
Concatenates a list of objects as a String.- Parameters:
list
- The list of objects to concatenate.- Returns:
- A text representation of the concatenated objects.
-
getPackageAsPath
Return a package name as a relative path name- Parameters:
pckge
- package name to convert to a directory.- Returns:
- String directory path.
-
removeUnderScores
Deprecated.Use the org.apache.commons.util.StringUtils class instead. Using its firstLetterCaps() method in conjunction with a StringTokenizer will achieve the same result.Remove underscores from a string and replaces first letters with capitals. Other letters are changed to lower case.
For example
foo_bar
becomesFooBar
butfoo_barBar
becomesFooBarbar
.- Parameters:
data
- string to remove underscores from.- Returns:
- String
-
removeAndHump
'Camels Hump' replacement of underscores.
Remove underscores from a string but leave the capitalization of the other letters unchanged.
For example
foo_barBar
becomesFooBarBar
.- Parameters:
data
- string to hump- Returns:
- String
-
removeAndHump
'Camels Hump' replacement.
Remove one string from another string but leave the capitalization of the other letters unchanged.
For example, removing "_" from
foo_barBar
becomesFooBarBar
.- Parameters:
data
- string to humpreplaceThis
- string to be replaced- Returns:
- String
-
firstLetterCaps
Makes the first letter caps and the rest lowercase.
For example
fooBar
becomesFoobar
.- Parameters:
data
- capitalize this- Returns:
- String
-
capitalizeFirstLetter
Capitalize the first letter but leave the rest as they are.
For example
fooBar
becomesFooBar
.- Parameters:
data
- capitalize this- Returns:
- String
-
split
Create a string array from a string separated by delim- Parameters:
line
- the line to splitdelim
- the delimter to split by- Returns:
- a string array of the split fields
-
chop
Chop i characters off the end of a string. This method assumes that any EOL characters in String s and the platform EOL will be the same. A 2 character EOL will count as 1 character.- Parameters:
s
- String to chop.i
- Number of characters to chop.- Returns:
- String with processed answer.
-
chop
Chop i characters off the end of a string. A 2 character EOL will count as 1 character.- Parameters:
s
- String to chop.i
- Number of characters to chop.eol
- A String representing the EOL (end of line).- Returns:
- String with processed answer.
-
stringSubstitution
- Parameters:
argStr
-vars
-- Returns:
- Substituted String.
-
stringSubstitution
Perform a series of substitutions. The substitions are performed by replacing $variable in the target string with the value of provided by the key "variable" in the provided hashtable.- Parameters:
argStr
- target stringvars
- name/value pairs used for substitution- Returns:
- String target string with replacements.
-
fileContentsToString
Read the contents of a file and place them in a string object.- Parameters:
file
- path to file.- Returns:
- String contents of the file.
-
collapseNewlines
Remove/collapse multiple newline characters.- Parameters:
argStr
- string to collapse newlines in.- Returns:
- String
-
collapseSpaces
Remove/collapse multiple spaces.- Parameters:
argStr
- string to remove multiple spaces from.- Returns:
- String
-
sub
Replaces all instances of oldString with newString in line. Taken from the Jive forum package.- Parameters:
line
- original string.oldString
- string in line to replace.newString
- replace oldString with this.- Returns:
- String string with replacements.
-
stackTrace
Returns the output of printStackTrace as a String.- Parameters:
e
- A Throwable.- Returns:
- A String.
-
normalizePath
Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path after ".." and "." elements are resolved out. If the specified path attempts to go outside the boundaries of the current context (i.e. too many ".." path elements are present), returnnull
instead.- Parameters:
path
- Path to be normalized- Returns:
- String normalized path
-
select
If state is true then return the trueString, else return the falseString.- Parameters:
state
-trueString
-falseString
-- Returns:
- Selected result.
-
allEmpty
Check to see if all the string objects passed in are empty.- Parameters:
list
- A list ofString
objects.- Returns:
- Whether all strings are empty.
-
trimStrings
Trim all strings in a List. Changes the strings in the existing list.- Parameters:
list
-- Returns:
- List of trimmed strings.
- Since:
- 1.5
-
nullTrim
Trim the string, but pass a null through.- Parameters:
s
-- Returns:
- List of trimmed Strings.
- Since:
- 1.5
-