Package org.apache.tools.ant.util
Class StringUtils
java.lang.Object
org.apache.tools.ant.util.StringUtils
A set of helper methods related to string manipulation.
- 
Field SummaryFields
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleanendsWith(StringBuffer buffer, String suffix) Checks that a string buffer ends up with a given string.static StringConvenient method to retrieve the full stacktrace from a given exception.static Stringjoin(Object[] array, CharSequence separator) Joins the string representation of the elements of an array to a joined string with a given separator.static Stringjoin(Collection<?> collection, CharSequence separator) Joins the string representation of the elements of a collection to a joined string with a given separator.Splits up a string into a list of lines.static longparseHumanSizes(String humanSize) Takes a human readable size representation eg 10K a long value.static StringremovePrefix(String string, String prefix) Removes the prefix from a given string, if the string contains that prefix.static StringremoveSuffix(String string, String suffix) Removes the suffix from a given string, if the string contains that suffix.static StringDeprecated.static StringresolveBackSlash(String input) xml does not do "c" like interpretation of strings.Splits up a string where elements are separated by a specific character and return all elements.static StringtrimToNull(String inputString) 
- 
Field Details- 
LINE_SEPDeprecated.the line separator for this OS
 
- 
- 
Method Details- 
lineSplitSplits up a string into a list of lines. It is equivalent tosplit(data, '\n').- Parameters:
- data- the string to split up into lines.
- Returns:
- the list of lines available in the string.
 
- 
splitSplits up a string where elements are separated by a specific character and return all elements.- Parameters:
- data- the string to split up.
- ch- the separator character.
- Returns:
- the list of elements.
 
- 
replaceDeprecated.Replace occurrences into a string.- Parameters:
- data- the string to replace occurrences into
- from- the occurrence to replace.
- to- the occurrence to be used as a replacement.
- Returns:
- the new string with replaced occurrences.
 
- 
getStackTraceConvenient method to retrieve the full stacktrace from a given exception.- Parameters:
- t- the exception to get the stacktrace from.
- Returns:
- the stacktrace from the given exception.
 
- 
endsWithChecks that a string buffer ends up with a given string. It may sound trivial with the existing JDK API but the various implementation among JDKs can make those methods extremely resource intensive and perform poorly due to massive memory allocation and copying. See- Parameters:
- buffer- the buffer to perform the check on
- suffix- the suffix
- Returns:
- trueif the character sequence represented by the argument is a suffix of the character sequence represented by the StringBuffer object;- falseotherwise. Note that the result will be- trueif the argument is the empty string.
 
- 
resolveBackSlashxml does not do "c" like interpretation of strings. i.e. \n\r\t etc. this method processes \n, \r, \t, \f, \\ also subs \s -> " \n\r\t\f" a trailing '\' will be ignored- Parameters:
- input- raw string with possible embedded '\'s
- Returns:
- converted string
- Since:
- Ant 1.7
 
- 
parseHumanSizesTakes a human readable size representation eg 10K a long value. Doesn't support 1.1K or other rational values.- Parameters:
- humanSize- the amount as a human readable string.
- Returns:
- a long value representation
- Throws:
- Exception- if there is a problem.
- Since:
- Ant 1.7
 
- 
removeSuffixRemoves the suffix from a given string, if the string contains that suffix.- Parameters:
- string- String for check
- suffix- Suffix to remove
- Returns:
- the string with the suffix
 
- 
removePrefixRemoves the prefix from a given string, if the string contains that prefix.- Parameters:
- string- String for check
- prefix- Prefix to remove
- Returns:
- the string with the prefix
 
- 
joinJoins the string representation of the elements of a collection to a joined string with a given separator.- Parameters:
- collection- Collection of the data to be joined (may be null)
- separator- Separator between elements (may be null)
- Returns:
- the joined string
 
- 
joinJoins the string representation of the elements of an array to a joined string with a given separator.- Parameters:
- array- Array of the data to be joined (may be null)
- separator- Separator between elements (may be null)
- Returns:
- the joined string
 
- 
trimToNull- Parameters:
- inputString- String to trim
- Returns:
- null if the input string is null or empty or contain only empty spaces. It returns the input string without leading and trailing spaces otherwise.
 
 
- 
String.replace(CharSequence, CharSequence)now.