StringUtilities¶
-
public final class
StringUtilities
¶ A StringUtilities is a convenient class for handling some common text processing.
Author: Hugo Y. K. Lam
Methods¶
addLeadingCharacter¶
-
public static String
addLeadingCharacter
(String s, char c, int len)¶ Adds specified leading characters to the specified length. Nothing will be done if the length of the given string is equal to or greater than the specified length.
Parameters: - s – the source string.
- c – the leading character(s) to be added.
- len – the length of the target string.
Returns: the string after adding the specified leading character(s).
addLeadingSpace¶
-
public static String
addLeadingSpace
(String s, int len)¶ Adds leading spaces to the given string to the specified length. Nothing will be done if the length of the given string is equal to or greater than the specified length.
Parameters: - s – the source string.
- len – the length of the target string.
Returns: the string after adding leading spaces.
addLeadingZero¶
-
public static String
addLeadingZero
(String s, int len)¶ Adds leading zeros to the given string to the specified length. Nothing will be done if the length of the given string is equal to or greater than the specified length.
Parameters: - s – the source string.
- len – the length of the target string.
Returns: the string after adding leading zeros.
addPrefix¶
addSuffix¶
appendCharacter¶
-
public static String
appendCharacter
(String s, char c, int len)¶ Appends specified characters to the given string to the specified length. Nothing will be done if the length of the given string is equal to or greater than the specified length.
Parameters: - s – the source string.
- c – the character(s) to be appended.
- len – the length of the target string.
Returns: @return the string after appending the specified character(s).
appendSpace¶
-
public static String
appendSpace
(String s, int len)¶ Appends spaces to the given string to the specified length. Nothing will be done if the length of the given string is equal to or greater than the specified length.
Parameters: - s – the source string.
- len – the length of the target string.
Returns: @return the string after appending spaces.
appendZero¶
-
public static String
appendZero
(String s, int len)¶ Appends zeros to the given string to the specified length. Nothing will be done if the length of the given string is equal to or greater than the specified length.
Parameters: - s – the source string.
- len – the length of the target string.
Returns: the string after appending zeros.
concat¶
concat¶
-
public static String
concat
(String[] tokens, String tokenPrefix, String tokenSuffix, String delim)¶ Concatenates a string array (string tokens) into a string with the specified delimiter string, token’s prefix, and token’s suffix.
Parameters: - tokens – a string array to be concatenated.
- tokenPrefix – the token’s prefix to be concatenated.
- tokenSuffix – the token’s suffix to be concatenated.
- delim – the delimiter.
Returns: the concatenated string.
contains¶
-
public static boolean
contains
(String[] tokens, String target)¶ Checks if a given string array contains the specified search string.
Parameters: - tokens – a string array to be searched.
- target – the target search string.
Returns: true if the given string array contains the specified search string, false otherwise.
getLength¶
isAllDigit¶
isEmptyString¶
isWrappedWith¶
-
public static boolean
isWrappedWith
(String s, String prefix, String suffix)¶ Checks if the given string is wrapped with the specified prefix and suffix.
Parameters: - s – the string to be checked.
- prefix – the prefix.
- suffix – the suffix.
Returns: true if the given string is wrapped with the prefix and suffix.
parseBoolean¶
parseBoolean¶
parseDouble¶
parseDouble¶
parseInt¶
parseInt¶
parseLong¶
parseLong¶
removeLeadingCharacter¶
removeLeadingSpace¶
removeLeadingZero¶
repeat¶
toArray¶
toArray¶
toArray¶
toCharArray¶
toGMTString¶
toHexString¶
toString¶
-
public static String
toString
(Throwable e)¶ Returns a string representation of the given throwable object, empty string if it is null. The resulted string contains a cause trace of the given throwable object.
Parameters: - e – the throwable object for getting its string representation.
Returns: a string represenation of the given Object.
toString¶
tokenize¶
-
public static String[]
tokenize
(String str, String delim)¶ Tokenizes a given string according to the specified delimiters. The characters in the delim argument are the delimiters for separating tokens. Delimiter characters themselves will not be treated as tokens.
Parameters: - str – a string to be parsed.
- delim – the delimiters.
Returns: the tokens in a string array.
tokenize¶
-
public static String[]
tokenize
(String str, int fixedLength)¶ Tokenizes a given string according to a fixed length. If the last token’s length is less than the fixed length specified, it will be ignored.
Parameters: - str – a string to be parsed.
- fixedLength – the fixed length.
Returns: the tokens in a string array.
trim¶
trim¶
-
public static String
trim
(String s, String prefix, String suffix)¶ Trims the given string. If the given string starts with the specified prefix and ends with the specified suffix, both the prefix and the suffix will be trimmed out.
Parameters: - s – the string to be trimmed.
- prefix – the prefix.
- suffix – the suffix.
Returns: the trimmed string.
trimAndVerifySize¶
-
public static String
trimAndVerifySize
(String s, int size)¶ Trims a given string and then verifies its size against the specified size. If the sizes do not match, null will be returned.
Parameters: - s – the string to be trimmed and verified.
- size – the size for the verification.
Returns: the trimmed string or null if the size verification failed.