StringUtils extension

Extensions on String for real-world utility operations.

on

Properties

isAlpha → bool

Available on String, provided by the StringUtils extension

Returns true if this string contains only alphabetic characters.
no setter
isAlphanumeric → bool

Available on String, provided by the StringUtils extension

Returns true if this string contains only alphanumeric characters.
no setter
isDigits → bool

Available on String, provided by the StringUtils extension

Returns true if this string contains only digits (0–9).
no setter
isEmail → bool

Available on String, provided by the StringUtils extension

Returns true if this is a valid email address.
no setter
isHexColor → bool

Available on String, provided by the StringUtils extension

Returns true if this is a valid hexadecimal color (#RGB or #RRGGBB).
no setter
isIPv4 → bool

Available on String, provided by the StringUtils extension

Returns true if this is a valid IPv4 address.
no setter
isIPv6 → bool

Available on String, provided by the StringUtils extension

Returns true if this is a valid IPv6 address.
no setter
isPalindrome → bool

Available on String, provided by the StringUtils extension

Returns true if this string is a palindrome (case-insensitive).
no setter
isPhoneNumber → bool

Available on String, provided by the StringUtils extension

Returns true if this is a valid phone number (E.164 and common formats).
no setter
isStrongPassword → bool

Available on String, provided by the StringUtils extension

Returns true if this is a strong password: at least 8 characters, one uppercase, one lowercase, one digit, one special character.
no setter
isUrl → bool

Available on String, provided by the StringUtils extension

Returns true if this is a valid http:// or https:// URL.
no setter
vowelCount → int

Available on String, provided by the StringUtils extension

Returns the number of vowels in this string.
no setter
wordCount → int

Available on String, provided by the StringUtils extension

Returns the number of words in this string.
no setter

Methods

after(String pattern) → String

Available on String, provided by the StringUtils extension

Returns the substring after the first occurrence of pattern.
afterLast(String pattern) → String

Available on String, provided by the StringUtils extension

Returns the substring after the last occurrence of pattern.
append(String other) → String

Available on String, provided by the StringUtils extension

Appends other to this string.
before(String pattern) → String

Available on String, provided by the StringUtils extension

Returns the substring before the first occurrence of pattern.
beforeLast(String pattern) → String

Available on String, provided by the StringUtils extension

Returns the substring before the last occurrence of pattern.
between(String start, String end) → String

Available on String, provided by the StringUtils extension

Returns the substring between start and end delimiters.
capitalize() → String

Available on String, provided by the StringUtils extension

Returns a new string with the first character in upper case.
compactWhitespace() → String

Available on String, provided by the StringUtils extension

Replaces all runs of whitespace with a single space and trims.
constantize() → String

Available on String, provided by the StringUtils extension

Converts this string to a constant name (UPPER_SNAKE_CASE).
containsIgnoreCase(String other) → bool

Available on String, provided by the StringUtils extension

Returns true if this string contains other, ignoring case.
countOccurrences(String substring) → int

Available on String, provided by the StringUtils extension

Counts the number of non-overlapping occurrences of substring.
dropLeft(int n) → String

Available on String, provided by the StringUtils extension

Drops the first n characters. Returns empty string if n >= length.
dropLeftWhile(bool condition(String other)) → String

Available on String, provided by the StringUtils extension

Drops characters from the left while condition is true.
dropRight(int n) → String

Available on String, provided by the StringUtils extension

Drops the last n characters. Returns empty string if n >= length.
dropRightWhile(bool condition(String other)) → String

Available on String, provided by the StringUtils extension

Drops characters from the right while condition is true.
equalsIgnoreCase(String other) → bool

Available on String, provided by the StringUtils extension

Returns true if this string equals other, ignoring case.
escape() → String

Available on String, provided by the StringUtils extension

Escapes backslashes and double-quotes.
extractEmails() → List<String>

Available on String, provided by the StringUtils extension

Extracts all email addresses from this string.
extractNumbers() → List<num>

Available on String, provided by the StringUtils extension

Extracts all numbers (int and double) from this string.
extractUrls() → List<String>

Available on String, provided by the StringUtils extension

Extracts all http/https URLs from this string.
foreignKey() → String

Available on String, provided by the StringUtils extension

Converts this string to a foreign key name.
format(List<Object> args) → String

Available on String, provided by the StringUtils extension

Formats this string using positional placeholders {0}, {1}, etc.
formatMap(Map<String, Object> args) → String

Available on String, provided by the StringUtils extension

Formats this string using named placeholders {key}.
fromBase64() → String

Available on String, provided by the StringUtils extension

Decodes a Base64-encoded string back to a plain string.
humanize() → String

Available on String, provided by the StringUtils extension

Converts a string into a human-readable form by inserting spaces before uppercase letters and lowercasing the result.
initials({int max = 2}) → String

Available on String, provided by the StringUtils extension

Returns initials from a name string (up to max characters).
levenshteinDistance(String other) → int

Available on String, provided by the StringUtils extension

Returns the Levenshtein edit distance between this string and other.
mask({int keepFirst = 0, int keepLast = 4, String maskChar = '*'}) → String

Available on String, provided by the StringUtils extension

Masks this string, keeping keepFirst characters at the start and keepLast at the end, replacing the rest with maskChar.
pathize() → String

Available on String, provided by the StringUtils extension

Converts this string to a path name.
pluralize() → String

Available on String, provided by the StringUtils extension

Naively pluralizes this string by appending 's'.
prepend(String other) → String

Available on String, provided by the StringUtils extension

Prepends other to this string.
removePrefix(String prefix) → String

Available on String, provided by the StringUtils extension

Removes prefix from the start of this string if present.
removeSuffix(String suffix) → String

Available on String, provided by the StringUtils extension

Removes suffix from the end of this string if present.
removeWhitespace() → String

Available on String, provided by the StringUtils extension

Removes all whitespace (including internal spaces) from this string.
repeat(int times, {String separator = ''}) → String

Available on String, provided by the StringUtils extension

Repeats this string times times, joined by separator.
replaceAfterFirst(String pattern, String replacement) → String

Available on String, provided by the StringUtils extension

Replaces everything after the first occurrence of pattern.
replaceAfterLast(String pattern, String replacement) → String

Available on String, provided by the StringUtils extension

Replaces everything after the last occurrence of pattern.
replaceBeforeFirst(String pattern, String replacement) → String

Available on String, provided by the StringUtils extension

Replaces everything before the first occurrence of pattern.
replaceBeforeLast(String pattern, String replacement) → String

Available on String, provided by the StringUtils extension

Replaces everything before the last occurrence of pattern.
reverse() → String

Available on String, provided by the StringUtils extension

Reverses this string.
sequenceize() → String

Available on String, provided by the StringUtils extension

Converts this string to a sequence name.
similarityTo(String other) → double

Available on String, provided by the StringUtils extension

Returns a similarity score between 0.0 (completely different) and 1.0 (identical), based on Levenshtein distance.
stripHtml() → String

Available on String, provided by the StringUtils extension

Removes all HTML tags from this string.
tableize() → String

Available on String, provided by the StringUtils extension

Converts this string to a table name (pluralized snake_case).
titleCase() → String

Available on String, provided by the StringUtils extension

Capitalizes the first character of each word.
toBase64() → String

Available on String, provided by the StringUtils extension

Encodes this string to Base64.
toBytes() → List<int>

Available on String, provided by the StringUtils extension

Encodes this string to a UTF-8 byte list.
toCamelCase() → String

Available on String, provided by the StringUtils extension

Converts a string to camelCase.
toColor() → Color?

Available on String, provided by the StringUtils extension

Converts a hex color string to a Color. Returns null if the string is not a valid hex color.
toDotCase() → String

Available on String, provided by the StringUtils extension

Converts a string to dot.case.
toHtmlText() → String

Available on String, provided by the StringUtils extension

Escapes HTML special characters (<, >, &, ", ').
toKebabCase() → String

Available on String, provided by the StringUtils extension

Converts a string to kebab-case.
toPascalCase() → String

Available on String, provided by the StringUtils extension

Converts a string to PascalCase.
toSentenceCase() → String

Available on String, provided by the StringUtils extension

Converts this string to sentence case (first letter uppercase, rest lower).
toSlug() → String

Available on String, provided by the StringUtils extension

Converts this string to a URL-friendly slug.
toSnakeCase() → String

Available on String, provided by the StringUtils extension

Converts a camelCase or PascalCase string to snake_case.
toTrainCase() → String

Available on String, provided by the StringUtils extension

Converts a string to Train-Case.
truncate(int maxLength, {String ellipsis = '…'}) → String

Available on String, provided by the StringUtils extension

Truncates this string to maxLength characters, appending ellipsis if truncation occurs.
truncateWords(int maxWords, {String ellipsis = '…'}) → String

Available on String, provided by the StringUtils extension

Truncates this string to maxWords words, appending ellipsis if truncation occurs.
tryParseJson() → dynamic

Available on String, provided by the StringUtils extension

Tries to parse this string as JSON. Returns null on failure.
uncapitalize() → String

Available on String, provided by the StringUtils extension

Returns a new string with the first character in lower case.
underscore() → String

Available on String, provided by the StringUtils extension

Converts a camelized string to all lower case separated by underscores.
variablize() → String

Available on String, provided by the StringUtils extension

Converts this string to a variable name (camelCase, no special chars).
wordWrap(int maxWidth) → String

Available on String, provided by the StringUtils extension

Wraps this string at maxWidth characters, breaking at word boundaries.