StringExtension extension

Null-safe validation, parsing, formatting, and conversion helpers for strings.

on

Properties

date DateTime?

Available on String?, provided by the StringExtension extension

Returns DateTime if string is a date string like "2025-01-01 12:00:00"
no setter
dateOnly DateTime?

Available on String?, provided by the StringExtension extension

Returns DateTime if string is a date string like "2025-01-01"
no setter
ipv4Tov6 String?

Available on String?, provided by the StringExtension extension

Convert an IPv4 address to an IPv6 address,
no setter
ipv6Tov4 String?

Available on String?, provided by the StringExtension extension

Convert an IPv6 address to an IPv4 address,
no setter
isBlank bool

Available on String?, provided by the StringExtension extension

Returns true if string is null, empty, or only whitespace.
no setter
isChineseFullName bool

Available on String?, provided by the StringExtension extension

Returns true if name is a valid Chinese full name.
no setter
isChineseIdNumber bool

Available on String?, provided by the StringExtension extension

Returns true if this string is a valid Chinese resident ID number.
no setter
isCreditCard bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid credit card number
no setter
isDate bool

Available on String?, provided by the StringExtension extension

Returns true if string is a date
no setter
isDEANumberOfUS bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid US Drug Enforcement Agency
no setter
isEmail bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid email address
no setter
isEmpty bool

Available on String?, provided by the StringExtension extension

Returns true if string is null or empty
no setter
isIPAddress bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid IPv4 or IPv6 address
no setter
isIPv4 bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid IPv4 address
no setter
isIPv6 bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid IPv6 address
no setter
isJson bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid JSON string
no setter
isNotBlank bool

Available on String?, provided by the StringExtension extension

Returns true if string has at least one non-whitespace character.
no setter
isNotEmpty bool

Available on String?, provided by the StringExtension extension

Returns true if string is not empty
no setter
isNumeric bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid number
no setter
isPhoneNumberOfUS bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid US Phone Number
no setter
isQuery bool

Available on String?, provided by the StringExtension extension

Validates URL query string (handles ? & # fragments, allows empty values)
no setter
isSSNofUS bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid US Society Security Number
no setter
isStrongPassword bool

Available on String?, provided by the StringExtension extension

Returns true if string match strong password requirements
no setter
isTime bool

Available on String?, provided by the StringExtension extension

Returns true if string is a time
no setter
isUrl bool

Available on String?, provided by the StringExtension extension

Returns true if string is a valid url
no setter
nullIfBlank String?

Available on String?, provided by the StringExtension extension

Returns null when this string is null, empty, or only whitespace.
no setter
orEmpty String

Available on String?, provided by the StringExtension extension

Returns this string, or an empty string when it is null.
no setter
time Time?

Available on String?, provided by the StringExtension extension

Returns Time if string is a time string like "12:00:00"
no setter
timeOnly Time?

Available on String?, provided by the StringExtension extension

Returns Time if string is a time string like "12:00:00"
no setter
trimmed String

Available on String?, provided by the StringExtension extension

Returns a trimmed string, or an empty string when it is null.
no setter

Methods

bytes() List<int>

Available on String?, provided by the StringExtension extension

Returns a list of the UTF-16 code units of the string.
bytesChunks(int chunkSize) List<List<int>>

Available on String?, provided by the StringExtension extension

Splits the string's UTF-16 code units (bytes) into a list of chunks.
bytesCount() int

Available on String?, provided by the StringExtension extension

Calculates the byte count of a string, treating non-ASCII characters as 2 bytes.
capitalize({bool allWords = false}) String

Available on String?, provided by the StringExtension extension

Returns string with capitalized first letter.
chunks(int chunkSize) List<String>

Available on String?, provided by the StringExtension extension

Splits the string into a list of chunks of a specified size.
containsIgnoreCase(String other) bool

Available on String?, provided by the StringExtension extension

Returns true if this string contains other, ignoring letter case.
isValidFileExtension([List<String>? allowed]) bool

Available on String?, provided by the StringExtension extension

Returns true if string is a file
json() → dynamic

Available on String?, provided by the StringExtension extension

Returns JSON object if string is a valid JSON string
limit(int maxLength, {String ellipsis = '...'}) String

Available on String?, provided by the StringExtension extension

Limits this string to maxLength and appends ellipsis when truncated.
mask({int start = 0, int? end, String mask = '*'}) String

Available on String?, provided by the StringExtension extension

Masks the characters from start to end with mask.
numeric() num?

Available on String?, provided by the StringExtension extension

Returns double 0.564 from string percentage like "56.4%" Parses this string as a double literal and returns its value.
onlyDigits() String

Available on String?, provided by the StringExtension extension

Returns only the numeric digits from this string.
removeWhitespace() String

Available on String?, provided by the StringExtension extension

Returns a copy of this string with all whitespace removed.
reverse() String

Available on String?, provided by the StringExtension extension

Returns this string reversed by rune.
toCamelCase() String

Available on String?, provided by the StringExtension extension

Converts a string from snake_case or kebab-case to camelCase.
toSnakeCase({String separator = '_'}) String

Available on String?, provided by the StringExtension extension

Converts a string from camelCase to snake_case.