StringUtils class
π StringUtils
β A collection of common string manipulation utilities.
This class provides static methods for checking string properties, modifying, formatting, parsing, and cleaning strings. It aims to simplify typical string-related tasks like trimming, tokenizing, quoting, and path manipulation.
π¦ Example Usage:
StringUtils.hasText(' hello '); // true
StringUtils.trimAllWhitespace(' a b '); // 'ab'
StringUtils.countOccurrencesOf('abcabc', 'a'); // 2
StringUtils.cleanPath('/foo/../bar'); // '/bar'
StringUtils.tokenizeToStringArray('a,b;c', ',;'); // ['a', 'b', 'c']
All methods are static and null-safe where applicable.
Properties
- hashCode β int
-
The hash code for this object.
no setterinherited
- runtimeType β Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) β dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) β String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) β bool -
The equality operator.
inherited
Static Methods
-
capitalize(
String str) β String - Capitalize first letter
-
cleanPath(
String path) β String - Clean path by normalizing separators and resolving . and ..
-
collectionToCommaDelimitedString(
Iterable? collection) β String - Convert collection to comma delimited string
-
collectionToDelimitedString(
Iterable? collection, String delimiter, [String prefix = '', String suffix = '']) β String - Convert collection to delimited string
-
commaDelimitedListToSet(
String? str) β Set< String> - Convert comma delimited list to set
-
commaDelimitedListToStringList(
String? str) β List< String> - Convert comma delimited list to string array
-
containsWhitespace(
String? str) β bool - Check if a string contains whitespace
-
countOccurrencesOf(
String str, String sub) β int - Count occurrences of substring in string
-
delete(
String inString, String pattern) β String - Delete all occurrences of pattern
-
deleteAny(
String inString, String? charsToDelete) β String - Delete any character in charsToDelete
-
delimitedListToStringArray(
String? str, String? delimiter) β List< String> - Convert delimited list to string array
-
endsWithIgnoreCase(
String? str, String? suffix) β bool - Test if string ends with suffix, ignoring case
-
getFilename(
String? path) β String? - Extract filename from path
-
getFilenameExtension(
String? path) β String? - Extract file extension from path
-
hasLength(
String? str) β bool - Check if a string has length
-
matchesCharacter(
String? str, String singleCharacter) β bool - Check if string matches character
-
quote(
String? str) β String? - Quote a string with single quotes
-
replace(
String inString, String oldPattern, String newPattern) β String - Replace all occurrences of oldPattern with newPattern
-
split(
String? toSplit, String? delimiter) β List< String> ? - Split string at first occurrence of delimiter
-
startsWithIgnoreCase(
String? str, String? prefix) β bool - Test if string starts with prefix, ignoring case
-
stripFilenameExtension(
String path) β String - Strip filename extension
-
tokenizeToStringArray(
String? str, String delimiters, [bool trimTokens = true, bool ignoreEmptyTokens = true]) β List< String> -
Tokenizes a string into a list using multiple
delimiters
. -
trimAllWhitespace(
String str) β String - Trim all whitespace from a string
-
trimLeadingCharacter(
String str, String leadingCharacter) β String - Trim leading character from string
-
trimTrailingCharacter(
String str, String trailingCharacter) β String - Trim trailing character from string
-
truncate(
String str, [int threshold = 100]) β String - Truncate string
-
uncapitalize(
String str) β String - Uncapitalize first letter
-
unqualify(
String qualifiedName, [String separator = '.']) β String - Unqualify a string by removing everything before the last dot