Package com.jk.core.util
Class JKStringUtil
java.lang.Object
com.jk.core.util.JKStringUtil
This class is a utility class used for string manipulation and formatting.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
capitalizeFully
(String label) This method capitalizes all the words in a string, converting the first character of each word to upper-case and the rest to lower-case.static String
This method compiles a SQL statement by replacing place-holders with parameter values.static String
This method concatenates multiple objects into a single string, separated by a space.static String
concatIgnoreNull
(String... list) This method concatenates an array of strings, ignoring null values.static void
copyToClipboard
(String text) This method copies the provided text to the system clip board.static String
escapeValue
(String value) This method escapes single quotes in a given string by adding a backslash before each single quote.static String
This method fixes the formatting of a value by capitalizing words and handling line breaks.static String
getFirstLine
(String message) This method retrieves the first line of a multi-line string or the entire string if it's a single line.static boolean
This method checks if a given string is empty or consists of only whitespace characters.static void
This main method demonstrates the utility of this class.static String
This method converts a singular noun to its plural form using predefined rules.static String
removeExtraSpaces
(String number) This method removes extra spaces from the provided string.static StringBuilder
removeLast
(StringBuilder builder, String string) This method removes the last occurrence of a specified substring from a StringBuilder.static String
removeLast
(String original, String string) This method removes the last occurrence of a specified substring from the original string.static String
setParameters
(String value, Object[] params) This method sets parameters in a string template by replacing place-holders with values.static String
This method truncates or pads the given string to the specified size.static String
This method trims leading and trailing whitespace from a string.
-
Constructor Details
-
JKStringUtil
public JKStringUtil()
-
-
Method Details
-
compile
This method compiles a SQL statement by replacing place-holders with parameter values.- Parameters:
sql
- Specifies the SQL statement with place-holders.param
- Specifies the parameter values to be inserted into the SQL statement.- Returns:
- the compiled SQL statement.
-
fixValue
This method fixes the formatting of a value by capitalizing words and handling line breaks.- Parameters:
value
- Specifies the value to be formatted.- Returns:
- the formatted value.
-
setParameters
This method sets parameters in a string template by replacing place-holders with values.- Parameters:
value
- Specifies the string template with place-holders.params
- Specifies the values to be inserted into the template.- Returns:
- the string with replaced place-holders
-
trim
This method trims leading and trailing whitespace from a string.- Parameters:
str
- Specifies the input string to be trimmed.- Returns:
- the trimmed string.
-
capitalizeFully
This method capitalizes all the words in a string, converting the first character of each word to upper-case and the rest to lower-case.- Parameters:
label
- Specifies the input string to be capitalized.- Returns:
- the capitalized string with the first character of each word in upper-case and the rest in lower-case.
-
removeLast
This method removes the last occurrence of a specified substring from the original string.- Parameters:
original
- Specifies the original string from which the substring will be removed.string
- Specifies the substring to be removed from the original string.- Returns:
- the new string with the last occurrence of the specified substring removed, or the original string if the substring is not found.
-
escapeValue
This method escapes single quotes in a given string by adding a backslash before each single quote.The resulting string is enclosed in single quotes.
- Parameters:
value
- Specifies the input string that needs to have its single quotes escaped.- Returns:
- the new string with single quotes escaped by adding a backslash before each single quote, and enclosed within single quotes.
-
isEmpty
This method checks if a given string is empty or consists of only whitespace characters.- Parameters:
str
- Specifies the string to be checked for emptiness.- Returns:
- true, if the string is `null` or contains only whitespace characters, false otherwise.
-
concat
This method concatenates multiple objects into a single string, separated by a space.- Parameters:
msg
- Specifies the objects to be concatenated.- Returns:
- a string containing the concatenated values of the provided objects, separated by a space.
-
getFirstLine
This method retrieves the first line of a multi-line string or the entire string if it's a single line.- Parameters:
message
- Specifies the input string.- Returns:
- the first line of the input string if it's multi-line, otherwise the entire input string.
-
removeLast
This method removes the last occurrence of a specified substring from a StringBuilder.- Parameters:
builder
- Specifies the StringBuilder from which to remove the substring.string
- Specifies the substring to be removed.- Returns:
- a new StringBuilder with the last occurrence of the substring removed, or the original StringBuilder if the substring is not found.
-
copyToClipboard
This method copies the provided text to the system clip board.- Parameters:
text
- Specifies the text to be copied to the clip board.
-
removeExtraSpaces
This method removes extra spaces from the provided string.- Parameters:
number
- Specifies the string from which to remove extra spaces.- Returns:
- the input string with extra spaces removed.
-
plurize
This method converts a singular noun to its plural form using predefined rules.- Parameters:
singular
- Specifies the singular noun to be pluralized.- Returns:
- the plural form of the input singular noun.
-
setSize
This method truncates or pads the given string to the specified size.- Parameters:
value
- Specifies the string to be resized.size
- Specifies the desired size of the string.- Returns:
- the resized string. If the input string is shorter than the specified size, it will be padded with spaces. If the input string is longer, it will be truncated.
-
main
This main method demonstrates the utility of this class.- Parameters:
args
- the command-line arguments.
-
concatIgnoreNull
This method concatenates an array of strings, ignoring null values.- Parameters:
list
- Specifies the array of strings to be concatenated.- Returns:
- the single string resulting from the concatenation of non-null values in the array.
-