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