StringExtension extension

Extension utilities for nullable Strings.

Includes helpers for numeric parsing, date formatting, currency formatting, validation, masking, capitalization, and other commonly used transformations.

on

Properties

capitalize String

Available on String?, provided by the StringExtension extension

Capitalizes the first letter of the string.
no setter
capitalizeWords String

Available on String?, provided by the StringExtension extension

Capitalizes every word in the string.
no setter
isNumeric bool

Available on String?, provided by the StringExtension extension

Checks whether the string contains only numbers.
no setter
removeWhitespace String

Available on String?, provided by the StringExtension extension

Removes all whitespace characters.
no setter

Methods

containsAny({required List<String> patterns}) bool

Available on String?, provided by the StringExtension extension

Checks if the string contains ANY of provided patterns.
formatDateString({String? originFormat, String targetFormat = 'dd/MM/yyyy'}) String

Available on String?, provided by the StringExtension extension

Converts a date string into a desired target format.
formatTimestampEpoch({String targetFormat = 'dd MM yyyy'}) String?

Available on String?, provided by the StringExtension extension

Interprets the string as an epoch timestamp (milliseconds) and formats it according to targetFormat.
mask({int? start, int? end, String maskChar = '*'}) String

Available on String?, provided by the StringExtension extension

Masks part of the string for privacy.
numericOnly() String?

Available on String?, provided by the StringExtension extension

Returns only the numeric characters from the string.
safe() String

Available on String?, provided by the StringExtension extension

Returns the empty strung if null.
spaceEvery({int every = 4, String spacer = ' '}) String

Available on String?, provided by the StringExtension extension

Inserts a space every every characters.
toBool() bool?

Available on String?, provided by the StringExtension extension

Converts string to boolean (case-insensitive).
toCurrency({CurrencyCountry country = CurrencyCountry.ID, bool usingSymbol = true, int decimalDigits = 0}) String

Available on String?, provided by the StringExtension extension

Converts the numeric string into formatted currency using CurrencyCountry.
toDateTime({String? originFormat, bool asLocal = true}) DateTime?

Available on String?, provided by the StringExtension extension

Parameters:
toDouble() double?

Available on String?, provided by the StringExtension extension

Converts a numeric string to a double. Returns null if parsing fails or string is empty.
toInt() int?

Available on String?, provided by the StringExtension extension

Converts a numeric string to an integer. Returns null if parsing fails or string is empty.
toRupiah({bool usingSymbol = true}) String

Available on String?, provided by the StringExtension extension

Converts the numeric string to Indonesian Rupiah formatted string.
truncate(int maxLength, {String suffix = '...'}) String

Available on String?, provided by the StringExtension extension

Truncates the string safely.