StringExtensions extension

Extensions on String for validation and transformation.

on

Methods

after(String delimiter) String

Available on String, provided by the StringExtensions extension

Part after the first occurrence of delimiter, or the whole string if absent.
before(String delimiter) String

Available on String, provided by the StringExtensions extension

Part before the first occurrence of delimiter, or the whole string if absent.
between(String start, String end) String?

Available on String, provided by the StringExtensions extension

Text between start and end, or null if markers are missing or out of order.
capitalize() String

Available on String, provided by the StringExtensions extension

Capitalizes the first letter of the string.
collapseWhitespace() String

Available on String, provided by the StringExtensions extension

Replaces runs of whitespace with a single space, trimming ends.
containsDigit() bool

Available on String, provided by the StringExtensions extension

Checks if the string contains at least one digit.
containsLowercase() bool

Available on String, provided by the StringExtensions extension

Checks if the string contains at least one lowercase letter.
containsSpecialCharacter() bool

Available on String, provided by the StringExtensions extension

Whether the string contains at least one non-alphanumeric character.
containsUppercase() bool

Available on String, provided by the StringExtensions extension

Checks if the string contains at least one uppercase letter.
countOccurrences(String pattern) int

Available on String, provided by the StringExtensions extension

Number of (non-overlapping) occurrences of pattern.
initials({int max = 2}) String

Available on String, provided by the StringExtensions extension

Uppercase initial letters (up to max words), useful for avatars.
isAlphabetic() bool

Available on String, provided by the StringExtensions extension

Checks if the string contains only alphabetic characters.
isAlphanumeric() bool

Available on String, provided by the StringExtensions extension

Whether the string contains only letters and digits.
isEmail() bool

Available on String, provided by the StringExtensions extension

Checks if the string is a valid email.
isJson() bool

Available on String, provided by the StringExtensions extension

Whether the string is valid JSON (object or array).
isNullOrWhiteSpace() bool

Available on String, provided by the StringExtensions extension

Returns true if the string is null, empty, or contains only whitespace.
isNumeric() bool

Available on String, provided by the StringExtensions extension

Returns true if the string contains only numeric characters.
isPhoneNumber() bool

Available on String, provided by the StringExtensions extension

Checks if the string is a valid phone number (basic check).
isStrongPassword({int minLength = 8, bool requireUppercase = true, bool requireLowercase = true, bool requireDigit = true, bool requireSpecial = true}) bool

Available on String, provided by the StringExtensions extension

Whether the string meets common password strength rules.
isUrl() bool

Available on String, provided by the StringExtensions extension

Checks if the string is a valid URL.
masked({int visibleCount = 4, String mask = '*'}) String

Available on String, provided by the StringExtensions extension

Masks all but the last visibleCount characters.
onlyDigits() String

Available on String, provided by the StringExtensions extension

Keeps only digit characters.
removeWhitespace() String

Available on String, provided by the StringExtensions extension

Removes all whitespace from the string.
replaceLast(String from, String to) String

Available on String, provided by the StringExtensions extension

Replaces the last occurrence of from with to.
reverse() String

Available on String, provided by the StringExtensions extension

Returns a reversed version of the string.
slugify() String

Available on String, provided by the StringExtensions extension

Lowercases, collapses whitespace and non-alphanumerics into single hyphens.
toBool() bool?

Available on String, provided by the StringExtensions extension

Parses boolean-ish strings: true/yes/1/y -> true, false/no/0/n -> false, otherwise null.
toCamelCase() String

Available on String, provided by the StringExtensions extension

Converts to camelCase.
toDoubleSafe() double?

Available on String, provided by the StringExtensions extension

Parses as double, or null if not a valid number.
toIntSafe() int?

Available on String, provided by the StringExtensions extension

Parses as int, or null if not a valid integer.
toKebabCase() String

Available on String, provided by the StringExtensions extension

Converts to kebab-case.
toPascalCase() String

Available on String, provided by the StringExtensions extension

Converts to PascalCase (Title Case without spaces).
toSnakeCase() String

Available on String, provided by the StringExtensions extension

Converts to snake_case.
toTitleCase() String

Available on String, provided by the StringExtensions extension

Converts the string to Title Case.
truncate(int maxLength, {String ellipsis = '...'}) String

Available on String, provided by the StringExtensions extension

Shortens the string to a specified length with an optional ellipsis.
withoutDigits() String

Available on String, provided by the StringExtensions extension

Removes all digit characters.