StringX extension

Main extension on String providing comprehensive conversion and formatting tools.

on

Properties

blankToNull String?

Available on String, provided by the StringX extension

Returns null if blank, otherwise this. Useful for form validation chains.
no setter
isAlpha bool

Available on String, provided by the StringX extension

Returns true if the string only contains letters.
no setter
isAlphanumeric bool

Available on String, provided by the StringX extension

Returns true if the string only contains letters and numbers.
no setter
isBlank bool

Available on String, provided by the StringX extension

Returns true if the string is purely whitespace or empty.
no setter
isEmail bool

Available on String, provided by the StringX extension

Returns true if the string is a valid email format.
no setter
isNotBlank bool

Available on String, provided by the StringX extension

Returns true if the string contains non-whitespace characters.
no setter
isNumeric bool

Available on String, provided by the StringX extension

Returns true if the string represents a valid number.
no setter
isUrl bool

Available on String, provided by the StringX extension

Returns true if the string is a valid URL.
no setter
jsonDecodeOrNull → dynamic

Available on String, provided by the StringX extension

Decodes JSON, returns null on failure instead of throwing.
no setter
readingTimeMinutes int

Available on String, provided by the StringX extension

Estimates the reading time in minutes (225 words per minute).
no setter
removeWhitespace String

Available on String, provided by the StringX extension

Removes all whitespace, including internal.
no setter
reversed String

Available on String, provided by the StringX extension

Reverses the string (Unicode-safe via runes).
no setter
toBool bool

Available on String, provided by the StringX extension

Parses string as boolean ('true' evaluates to true, else false).
no setter
toCamelCase String

Available on String, provided by the StringX extension

'Hello World''helloWorld'
no setter
toDoubleOrNull double?

Available on String, provided by the StringX extension

Parses to double, returns null on failure.
no setter
toDoubleOrZero double

Available on String, provided by the StringX extension

Parses to double, returns 0.0 on failure.
no setter
toDurationOrNull Duration?

Available on String, provided by the StringX extension

Parses "SS", "MM:SS", or "HH:MM:SS" into a Duration, returns null on failure.
no setter
toIntOrNull int?

Available on String, provided by the StringX extension

Parses to int, returns null on failure.
no setter
toIntOrZero int

Available on String, provided by the StringX extension

Parses to int, returns 0 on failure.
no setter
toKebabCase String

Available on String, provided by the StringX extension

'Hello World' / 'helloWorld''hello-world'
no setter
toScreamingSnakeCase String

Available on String, provided by the StringX extension

'hello world''HELLO_WORLD'
no setter
toSentenceCase String

Available on String, provided by the StringX extension

Capitalizes only the first character.
no setter
toSlug String

Available on String, provided by the StringX extension

URL-safe slug: lowercased, spaces→hyphens, non-alphanumeric stripped. 'Hello World! 2024''hello-world-2024'
no setter
toSnakeCase String

Available on String, provided by the StringX extension

'Hello World' / 'helloWorld''hello_world'
no setter
toTitleCase String

Available on String, provided by the StringX extension

Capitalizes the first letter of each whitespace-delimited word.
no setter
toUriOrNull Uri?

Available on String, provided by the StringX extension

Parses string to Uri, returns null on failure.
no setter

Methods

countOccurrences(String pattern) int

Available on String, provided by the StringX extension

Counts non-overlapping occurrences of pattern.
hasLengthBetween(int min, int max) bool

Available on String, provided by the StringX extension

Passes if length falls within [min, max] after trimming.
repeat(int count) String

Available on String, provided by the StringX extension

Repeats this string count times.
toDuration() Duration

Available on String, provided by the StringX extension

Parses "SS", "MM:SS", or "HH:MM:SS" into a Duration.
truncate(int maxLength, {String ellipsis = '...'}) String

Available on String, provided by the StringX extension

Truncates to maxLength chars, appending ellipsis if cut.
truncateWords(int maxLength, {String ellipsis = '...'}) String

Available on String, provided by the StringX extension

Truncates at a word boundary instead of mid-word.
wrap(String prefix, [String? suffix]) String

Available on String, provided by the StringX extension

Wraps the string with prefix and suffix (defaults to prefix).