Defines the all lower case format (All letters on a string written with lower case letters only)
Defines the all upper case format (All letters on a string written with Capital letters only)
Defines the CamelCase format (the practice of writing compound words or phrases such that each word or abbreviation begins with a capital letter)
Defines the first upper rest lower case format (All letters on a string written with lower case letters except the first one which is Capitalized)
Defines the lowerCamelCase format variation that writes first letter as lower case
Defines the lower_snake_case format variation that writes all letters as lower case
Defines the sentence case format (Only the first character of the sentence is capitalised,except for proper nouns and other words which are required by a more specific rule to be capitalised). Generally equivalent to the baseline universal standard of formal English orthography
Defines the snake_case format (the practice of writing compound words or phrases in which the elements are separated with one underscore character (_) and no spaces)
Defines the start case format (The first character in all words capitalised and all the rest of the word lower case). It is also called Title Case
Defines the UpperCamelCase format variation that writes first letter as upper case
Defines the FORMAT_UPPER_SNAKE_CASE format variation that writes all letters as upper case
Compares two strings and gives the number of character replacements that must be performed to convert one of the strings into the other. A very useful method to use in fuzzy text searches where we want to look for similar texts. This method uses the Levenshtein method for the comparison:
The Levenshtein distance is defined as the minimal number of characters you have to replace, insert or delete to transform string1 into string2. The complexity of the algorithm is O(m*n), where n and m are the length of string1 and string2.
The first string to compare
The second string to compare
The number of characters to replace to convert $string1 into $string2 where 0 means both strings are the same. The higher the result, the more different the strings are.
Compares the percentage of similarity between two strings, based on the Levenshtein method. A very useful method to use in fuzzy text searches where we want to look for similar texts.
The first string to compare
The second string to compare
A number between 0 and 100, being 100 if both strings are the same and 0 if both strings are totally different
Count the number of characters that match the given letter case on the given string
The string which case matching characters will be counted
Defines which letter case are we looking for: StringUtils.FORMAT_ALL_UPPER_CASE or StringUtils.FORMAT_ALL_LOWER_CASE
The number of characters with the specified letter case that are present on the string
Given a string with a list of elements separated by '/' or '' that represent some arbitrary path structure, this method will return the number of elements that are listed on the path.
A string containing some arbitrary path.
The number of elements that are listed on the provided path
Count the number of times a string is found inside another string
The string where we want to search
The string that we want to look for
The number of times that findMe appears on string
Count the number of words that exist on the given string
The string which words will be counted
' ' by default. The character that is considered as the word sepparator
The number of words (elements divided by the wordSeparator value) that are present on the string
Strictly check that the provided value is a non empty string or throw an exception
Uses the same criteria as the StringUtils.isEmpty() method
A value to check
The name of the value to be shown at the beginning of the exception message
The rest of the exception message
void
Strictly check that the provided value is a string or throw an exception
A value to check
The name of the value to be shown at the beginning of the exception message
The rest of the exception message
void
Changes the letter case for the given string to the specified format.
A string that will be processed to match the specified case format.
The format to which the given string will be converted. Possible values are defined as StringUtils constants that start with FORMAT_, like: StringUtils.FORMAT_ALL_UPPER_CASE
The given string converted to the specified case format.
Full text search is the official name for the process of searching on a big text content based on a string containing some text to find. This method will process a text so it removes all the accents and non alphanumerical characters that are not usefull for searching on strings, convert everything to lower case and remove empty spaces. To perform the search it is important that both search and searched strings are standarized the same way, to maximize possible matches.
String to process
The character that will be treated as the word separator. By default it is the empty space character ' '
The resulting string
Given a string with a list of elements separated by '/' or '' that represent some kind of unformatted path, this method will process it to get a standarized one by applying the following rules:
NOTE: This method only applies format to the received string. It does not check if the path is a real location or a valid url, and won't also fail if the received path contains strange characters or is invalid.
A raw path to be formatted
The character to use as the element divider. Only slash '/' or backslash '' are allowed.
The correctly formatted path without any trailing separator
Given a raw string containing an internet URL, this method will process it to obtain a URL that is 100% format valid.
A Uniform Resource Locator (URL), commonly informally termed a web address is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. URLs occur most commonly to reference web pages (http), but are also used for file transfer (ftp), email (mailto), database access (JDBC), and many other applications.
Every HTTP URL conforms to the syntax of a generic URI. A generic URI is of the form: scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
The formated url string or the original string if it was not a valid url
Generate a path string from an array of elements.
An array of elements that will be used to form the path.
An optional separator that will be used to join the elements in the path. Defaults to /
.
A string representing the path formed from the given elements.
Generates a random string with the specified length and options
Specify the minimum possible length for the generated string
Specify the maximum possible length for the generated string
Defines the list of possible characters to be generated. Each element of charSet must be a string containing the possible characters like 'a1kjuhAO' or a range like 'a-z', 'A-D', '0-5', ... etc. Note that - character must be escaped - when not specified as part of a range. Default charset is alphanumeric ['0-9', 'a-z', 'A-Z']
A randomly generated string
Extracts the domain name from a given url (excluding subdomain). For example: http://subdomain.google.com/test/ will result in 'google.com'
A string containing an URL
The domain from the given string (excluding the subdomain if exists)
Extracts the hostname (domain + subdomain) from a given url. For example: http://subdomain.google.com/test/ will result in 'subdomain.google.com'
A string containing an URL
The domain and subdomain from the given string (subdomain.domain.com)
Extracts all the lines from the given string and outputs an array with each line as an element. It does not matter which line separator's been used (\n, \r, Windows, linux...). All source lines will be correctly extracted.
Text containing one or more lines that will be converted to an array with each line on a different element.
One or more regular expressions that will be used to filter unwanted lines. Lines that match any of the filters will be excluded from the result. By default, all empty lines are ignored (those containing only newline, blank, tabulators, etc..).
A list with all the string lines sepparated as different array elements.
Given a string with a list of elements separated by '/' or '' that represent some arbitrary path structure, this method will format the specified path and remove the number of requested path elements (from its right side) and return the path without that elements.
This method can be used with Operating system file paths, urls, or any other string that uses the 'slash separated' format to encode a path.
A string containing some arbitrary path.
(one by default) The number of elements that we want to remove from the right side of the path.
The character to use as the element divider for the returned path. Only slash '/' or backslash '' are allowed.
The received path without the specified number of elements and correctly formatted
Given a string with a list of elements separated by '/' or '' that represent some arbitrary path structure, this method will return the element that is located at the requested position. If no position is defined, by default the last element of the path will be returned (the most to the right one).
This method can be used with Operating system file paths, urls, or any other string that uses the 'slash separated' format to encode a path.
A string containing some arbitrary path.
The index for the element that we want to extract from the path. Positive values will get path elements starting from the left side, being 0 the first most to the left one. Negative values will get path elements starting from the right side, being -1 the last path element (or the first most to the right one). If not specified, the last one will be returned.
The element at the specified path position or the last one if no position is defined
This method works in the same way as getPathElement but it also removes the extension part from the result if it has any.
A string containing some arbitrary path.
The index for the element that we want to extract from the path. If not specified, the last one will be returned.
The character to be used as the extension separator. The most commonly used is '.'
The element at the specified path position with it's extension removed or the last one if no position is defined
This method works in the same way as getPathElement but it only gives the element extension if it has any.
A string containing some arbitrary path.
The index for the element extension that we want to extract from the path. If not specified, the last one will be returned.
The character to be used as the extension separator. The most commonly used is '.'
The extension from the element at the specified path position or the extension from the last one if no position is defined
Given an internet URL, this method extracts only the scheme part. Example: "http://google.com" -> results in "http"
A valid internet url
('ftp', 'http', ...) if the url is valid or '' if the url is invalid
Tells if a specified string is semantically empty, which applies to any string that is comprised of empty spaces, new line characters, tabulations or any other characters without a visually semantic value to the user.
Example1: Following strings are considered as empty: " ", "", " \n\n\n", " \t\t\n" Example2: Following strings are not considered as empty: "hello", " a", " \n\nB"
The text to check
Custom list of strings that will be also considered as empty characters. For example, we can define 'NULL' and '' as empty string values by setting this to ['NULL', '']
false if the string is not empty, true if the string contains non semantically valuable characters or any other characters defined as "empty" values
Checks if a given string ends with any of the specified values.
The string to check
An array of strings that the input string should end with.
True if the input string ends with any of the specified values, False otherwise.
Checks if the given string starts with any of the specified values.
The string to check
An array of strings that the input string should start with.
True if the input string starts with any of the specified values, False otherwise.
Tells if the given value is a string or not
A value to check
true if the given value is a string, false otherwise
Tells if the given string is a valid url or not
The value to check
False in case the validation fails or true if validation succeeds.
Method that limits the length of a string and optionally appends informative characters like ' ...' to inform that the original string was longer.
String to limit
Max number of characters
If the specified text exceeds the specified limit, the value of this parameter will be added to the end of the result. The value is ' ...' by default.
The specified string but limited in length if necessary. Final result will never exceed the specified limit, also with the limiterString appended.
Pad a string to a certain length with another string
The string to which we want to fill the empty spaces
The minimum length that we want for the resulting string to have
The character or characters which we want to add to the string to match the target length
LEFT to append the padString to the left of the string, RIGHT to append the padString to the right of the string
The padded string
Converts all accent characters to ASCII characters on a given string.
This method is based on a stack overflow implementation called removeDiacritics
Text from which accents must be cleaned
The given string with all accent and diacritics replaced by the respective ASCII characters.
Remove all duplicate consecutive fragments from the provided string and leave only one occurence
The string to process
A list with the fragments that will be removed when found consecutive. If this value is an empty array, all duplicate consecutive characters will be deleted. We can pass here words or special characters like "\n"
The string with a maximum of one consecutive sequence for all those matching the provided set
Replace all occurrences of the search string with the replacement string
The string or array being searched and replaced on, otherwise known as the haystack.
The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles (if we use an array, the order of replacement will be the same of the array: First element will be the first one to be replaced, second element the second, etc..)
The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.
If passed and > 0, this will define the maximum number of replacements to perform
The string with all the replaced values
This metod performs the same string replacement that replace() does, but instead of searching on a single string it will search on all the strings inside a given array or object.
The search is totally recursive and will be performed inside any arrays, objects, and combination of any of them. Any value that is not a string which is found inside the provided structure will be ignored
Method is non destructive: The provided structure is not altered, a copy is given
see StringUtils.replace
see StringUtils.replace
see StringUtils.replace
A copy of the provided object or array with all the values replaced on all its strings
Remove whitespaces (or any custom set of characters) from both sides of a string
A string to process
A set of characters that will be trimmed from both string sides. By default, empty space and new line characters are defined : " \n\r"
The trimmed string
Remove whitespaces (or any custom set of characters) from a string left side
A string to process
A set of characters that will be trimmed from string left side. By default, empty space and new line characters are defined : " \n\r"
The trimmed string
Remove whitespaces (or any custom set of characters) from a string right side
A string to process
A set of characters that will be trimmed from string right side. By default, empty space and new line characters are defined : " \n\r"
The trimmed string
Generated using TypeDoc
The most common string processing and modification utilities