Class Strings
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringChange instringoriginalbynewString.static StringIn the sent string changes the strings in toChange map for its values.static StringchangeLast(String string, String original, String newString) Change instring the last occurrence oforiginalbynewString.static StringchangeSeparatorsBySpaces(String string) Changes \n, \r and \t by space.static StringConcatenates the list of strings using the separator.static Collection<String> extractVariables(String text) Extract variables names inside ${} from a text.static Collection<String> extractVariables(String text, String startDelimiter, String endDelimiter) Extract variables names inside the indicate separators from a text.static StringfirstLower(String s) Returns a string like the sent one but with the first letter in lowercase.static StringfirstToken(String string, String delim) static StringfirstUpper(String s) Returns a string like the sent one but with the first letter in uppercase.static StringFix the length of the string filling with spaces if needed.static StringFix the length of the string filling with the specified character if needed.static booleanisJavaIdentifier(String input) static booleanisModelName(String string) Determines if the string is a valid model name.static booleanisNumeric(CharSequence string) The space, comma, dot, + and - are considered as numeric.static StringConvert a string with a Java identifier in label natural for a human.static Stringstatic Stringstatic StringReturns a String multiline platform independent.static StringnaturalLabelToIdentifier(String naturalLabel) Convert a string with a label natural for a human into a identifier valid to use as URL, file name, internal id, etc.static StringnoFirstToken(String string, String delim) All string but without first token.static StringnoFirstTokenWithoutFirstDelim(String string, String delim) All string but without first token.static StringnoLastToken(String string) All string but without last token.static StringnoLastToken(String string, String delim) All string but without last token.static StringnoLastTokenWithoutLastDelim(String string, String delim) All string but without last token.static StringremoveAccents(String value) Change from a vowel with an accent, to vowel with no accent If you send "Camión" it returns "Camion"static StringremoveBlanks(String string) Returns the argumentstringwithout blanks (\n, \r, \t, \f) or whitespace.static Objectstatic StringA key function of any application filtering process will be the removal of possible dangerous special characters.static StringCreates a string from repeating another string.static Stringspaces(int count) Creates a string with the specified blank spaces.static final String[]Converts a list of comma separated elements in a string array.static final String[]Converts a list of elements separated by a arbitrary character in a string array.static StringTranslate to the charset specified.static final Collection<String> toCollection(String list) Converts a list of comma separated elements in a string collection.static final Collection<String> toCollection(String list, String separator) Converts a list of elements separated by a arbitrary character in a string collection.Converts a list of comma separated elements in a string List.Converts a list of elements separated by a arbitrary character in a string List.static final ObjectConverts a string a object of the specified type.Converts a list of comma separated elements in a string set.Converts a list of elements separated by a arbitrary character in a string set.toSetNullByPass(String list) Converts a list of comma separated elements in a string set.static final StringTry to do a decent toString from a regular object.static final StringConverts an array of objects in a string of comma separated elements.static final StringConverts an array of objects in string of elements separated by a arbitrary character .static final StringtoString(Collection collection) Converts a collection of objects in a string of comma separated elements.static final StringtoString(Collection collection, String separator) Converts a collection of objects in string of elements separated by a arbitrary character .static final StringTry to do a decent toString from a regular object.static StringRemove the quotes from a sentence between quotes.static StringwrapVariables(String listOfVariables) Wrap each variable name in the list with ${}, preserving optional suffixes, like ASC/DESC.
-
Constructor Details
-
Strings
public Strings()
-
-
Method Details
-
concat
Concatenates the list of strings using the separator.For example, concat(" - ", "Juan", "Perico", "Andrés") returns "Juan - Perico - Andrés".
- Parameters:
separator- The character used as separator.strings- Strings to be concatenated. Can be null.- Returns:
- Not null, including the case strings == null.
- Since:
- 6.0
-
isNumeric
The space, comma, dot, + and - are considered as numeric.- Since:
- 5.1.1
-
changeSeparatorsBySpaces
-
toCharSet
Translate to the charset specified.- Parameters:
original- Original stringcharSet- Charset to traslate to, for example, UTF-8, or ISO-8859-1- Returns:
- The string translated
- Throws:
UnsupportedEncodingException- If charset is not supported
-
spaces
Creates a string with the specified blank spaces.- Parameters:
count- Quantity of spaces- Returns:
- Not null.
-
fix
Fix the length of the string filling with spaces if needed.Returns the sent string but with the specified length.
It fills or cuts as it needs.- Parameters:
string- Can be null, in which case empty string is assumedlength- Character count of result stringalign- Not null- Returns:
- Not null
-
fix
Fix the length of the string filling with the specified character if needed.Returns the sent string but with the specified length.
It fills or cuts as it needs.- Parameters:
string- Can be null, in which case empty string is assumedlength- Character count of result stringalign- Not nullfillCharacter- Character used to fill- Returns:
- Not null
-
repeat
-
toArray
Converts a list of comma separated elements in a string array.For example, the list Angel, Manolo, Antonia is converted to a array of 3 elements with this 3 names without comman nor spaces.
- Parameters:
list- String with the list. If null return a empty string- Returns:
- Not null, including the case list == null.
-
toArray
Converts a list of elements separated by a arbitrary character in a string array.For example, the list Angel : Manolo : Antonia is converted to a array of 3 elements with this 3 names without colon (for example) nor spaces.
- Parameters:
list- String with the list. If null return a empty stringseparator- The character used as separator.- Returns:
- Not null, including the case list == null.
-
toCollection
Converts a list of comma separated elements in a string collection.For example, the list Angel, Manolo, Antonia is converted to a collection of 3 elements with this 3 names without comman nor spaces.
- Parameters:
list- String with the list. If null return a empty string- Returns:
- Not null, including the case list == null.
-
toCollection
Converts a list of elements separated by a arbitrary character in a string collection.For example, the list Angel : Manolo : Antonia is converted to a collection of 3 elements with this 3 names without colon (for example) nor spaces.
- Parameters:
list- String with the list. If null return a empty stringseparator- The character used as separator.- Returns:
- Not null, including the case list == null.
-
toList
Converts a list of comma separated elements in a string List.For example, the list Angel, Manolo, Antonia is converted to a List of 3 elements with this 3 names without comma nor spaces.
- Parameters:
list- String with the list. If null return a empty string- Returns:
- Not null, including the case list == null.
- Since:
- 4.3
-
toList
Converts a list of elements separated by a arbitrary character in a string List.For example, the list Angel : Manolo : Antonia is converted to a List of 3 elements with this 3 names without colon (for example) nor spaces.
- Parameters:
list- String with the list. If null return a empty stringseparator- The character used as separator.- Returns:
- Not null, including the case list == null.
- Since:
- 4.3
-
toSet
Converts a list of comma separated elements in a string set.For example, the list Angel, Manolo, Antonia is converted to a set of 3 elements with this 3 names without comman nor spaces.
- Parameters:
list- String with the list. If null return a empty string- Returns:
- Not null, including the case list == null.
- Since:
- 4.1
-
toSetNullByPass
Converts a list of comma separated elements in a string set.For example, the list Angel, Manolo, Antonia is converted to a set of 3 elements with this 3 names without comman nor spaces.
- Parameters:
list- String with the list. If null return a empty string- Returns:
- Null in the case list == null.
- Since:
- 4.1
-
toSet
Converts a list of elements separated by a arbitrary character in a string set.For example, the list Angel : Manolo : Antonia is converted to a set of 3 elements with this 3 names without colon (for example) nor spaces.
- Parameters:
list- String with the list. If null return a empty stringseparator- The character used as separator.- Returns:
- Not null, including the case list == null.
- Since:
- 4.1
-
toString
Converts a collection of objects in a string of comma separated elements.For example, a collection of 3 elements with 3 names is converted to the string Angel, Manolo, Antonia
- Parameters:
collection- Collection with the elements. If null return an empty string- Returns:
- Not null, including the case collection == null.
-
toString
Converts a collection of objects in string of elements separated by a arbitrary character .For example, a collection of 3 elements with this 3 names is converted to a string of 3 elements with this 3 names and colon (for example).
- Parameters:
collection- A collection of objects. If null return an empty stringseparator- The character used as separator.- Returns:
- Not null, including the case collection == null.
-
toString
Converts an array of objects in a string of comma separated elements.For example, an array of 3 elements with 3 names is converted to the string Angel, Manolo, Antonia
- Parameters:
array- Array with the elements. If null return a empty string- Returns:
- Not null, including the case array == null.
- Since:
- 5.6
-
toString
Converts an array of objects in string of elements separated by a arbitrary character .For example, an array of 3 elements with this 3 names is converted to a string of 3 elements with this 3 names and colon (for example).
- Parameters:
array- An array of objects. If null return an empty stringseparator- The character used as separator.- Returns:
- Not null, including the case array == null.
- Since:
- 5.6
-
toString
-
toString
-
toObject
Converts a string a object of the specified type.Supports all primitive type plus its wrappers except char and void.
SupportStringandBigDecimaltoo.If there is conversion error or is a type not supporte return null or the default value for the type (zero for numeric).
- Parameters:
type- The type of returned object (can be a primitive type in this case return its wrapper). Not nullstring- String with data to convert. Can be null, in this case return a default value.
-
firstUpper
-
firstLower
-
change
-
change
Change instringoriginalbynewString.- Parameters:
string- String in which we make the changes. Can be nulloriginal- String to search. Not nullnewString- New value to put in place of original. Not null- Returns:
- The changed string, if the sent string is null a null is returned
-
changeLast
Change instring the last occurrence oforiginalbynewString.- Parameters:
string- String in which we make the changes. Can be nulloriginal- String to search. Not nullnewString- New value to put in place of original. Not null- Returns:
- The changed string, if the sent string is null a null is returned
-
lastToken
-
lastToken
-
noLastToken
-
noLastToken
-
noFirstToken
-
noFirstTokenWithoutFirstDelim
-
noLastTokenWithoutLastDelim
-
firstToken
-
removeXSS
-
removeXSS
-
isJavaIdentifier
- Since:
- 7.4.5
-
javaIdentifierToNaturalLabel
Convert a string with a Java identifier in label natural for a human.If you send "firstName" it returns "First name".
If you send "CustomerOrder" it returns "Customer order".
If you send "first_name" it returns "First name" (snake_case support since 7.4.1). -
naturalLabelToIdentifier
-
removeAccents
-
isModelName
Determines if the string is a valid model name.- Since:
- 4.5
-
removeBlanks
-
multiline
Returns a String multiline platform independent.For example,
Strings.multiline("OpenXava", "AJAX Java Framework Web", "You only have to write the domain classes") ->
"OpenXava
AJAX Java Framework Web
You only have to write the domain classes"- Parameters:
strings- The array of String objects, entries not may be null- Since:
- 5.7
-
unquote
Remove the quotes from a sentence between quotes.That is:
"Hi, I'm Peter" --> Hi, I'm Peter
- Parameters:
sentence- The original sentence, with or without surrounding quotes.- Returns:
- The sentence without quotes, if the sentence has no quotes returns the original string.
- Since:
- 5.8
-
extractVariables
Extract variables names inside ${} from a text.So, if you have "select ${number}, ${name} from ${customer} you get a collection with the strings "number", "name" and "customer".
- Parameters:
text- Text to examine, can be null.- Returns:
- The collection with the variable names, it never will be null.
- Since:
- 6.5.1
-
extractVariables
public static Collection<String> extractVariables(String text, String startDelimiter, String endDelimiter) Extract variables names inside the indicate separators from a text.So, if you have "select [number], [name] from [customer] and call sending "[" and "]" as delimiter, you get a collection with the strings "number", "name" and "customer".
- Parameters:
text- Text to examine, can be null.endDelimiter- The delimiter that finished a variable, like } or ].- Returns:
- The collection with the variable names, it never will be null.
- Since:
- 6.5.1
-
wrapVariables
Wrap each variable name in the list with ${}, preserving optional suffixes, like ASC/DESC.Examples: - "number, name" -> "${number}, ${name}" - "number desc" -> "${number} desc" - "${number} desc" -> "${number} desc" (left intact) - "customer.name, ${code} asc" -> "${customer.name}, ${code} asc"
- Parameters:
listOfVariables- List of comma-separated variable names, optionally with a suffix like ASC/DESC- Returns:
- The list with each variable wrapped; never null
- Since:
- 7.6
-