DHUNullSafeStringExtensions extension
Properties
-
asBool
→ bool
-
Converts the string into a boolean.
Returns true if the string is any of these values: "true", "yes", "1", or if the string is a number and greater than 0, false if less than 1. This is also case insensitive.
no setter
-
clean
→ String?
-
Removes all whitespace characters and collapses the string into a single line.
no setter
-
containsDigits
→ bool
-
Checks if the string contains any digits.
Example: "f1rstDate" => true, "firstDate" => false
no setter
-
hasCapitalLetter
→ bool
-
Checks if the string contains at least one capital letter.
no setter
-
hasNoSpecialChars
→ bool
-
Checks if the string does NOT contain any characters that are not letters, numbers, or spaces (i.e., special characters).
no setter
-
hasSpecialChars
→ bool
-
Checks if the string contains any characters that are not letters, numbers, or spaces (i.e., special characters).
no setter
-
isAlphabet
→ bool
-
Checks if the string consists only of letters (no whitespace).
no setter
-
isAlphanumeric
→ bool
-
Checks if the string contains only letters and numbers.
no setter
-
isBlank
→ bool
-
Returns true if the string is null, empty, or solely made of whitespace characters.
Alias for isEmptyOrNull.
no setter
-
isBool
→ bool
-
Checks if the string represents a boolean value.
no setter
-
isEmptyOrNull
→ bool
-
Returns true if the string is null, empty, or, after cleaning (collapsing into a single line, removing all whitespaces), is empty.
no setter
-
isNotBlank
→ bool
-
Returns true if the string is neither null, empty, nor solely made of whitespace characters.
Alias for isNotEmptyOrNull.
no setter
-
isNotEmptyOrNull
→ bool
-
Returns true if the string is not null, not empty, and, after cleaning (removing all whitespaces and collapsing into a single line), is not empty.
no setter
-
isNullOrWhiteSpace
→ bool
-
Indicates whether the string is null, empty, or consists only of whitespace characters.
no setter
-
isNumeric
→ bool
-
Checks if the string consists only of numbers (no whitespace).
no setter
-
isPalindrome
→ bool
-
Checks if the string is a palindrome.
no setter
-
isValidCurrency
→ bool
-
Checks if the string is a valid currency format.
no setter
-
isValidEmail
→ bool
-
Checks if the string is a valid email address.
no setter
-
isValidHTML
→ bool
-
Checks if the string is an HTML file or URL.
no setter
-
isValidIp4
→ bool
-
Checks if the string is a valid IPv4 address.
no setter
-
isValidIp6
→ bool
-
Checks if the string is a valid IPv6 address.
no setter
-
isValidPhoneNumber
→ bool
-
Checks if the string is a valid phone number.
no setter
-
isValidUrl
→ bool
-
Checks if the string is a valid URL.
no setter
-
isValidUsername
→ bool
-
Checks if the string is a valid username.
no setter
-
lastIndex
→ String
-
Returns the last character of the string.
no setter
-
orEmpty
→ String
-
Returns the string if it is not null, or the empty string otherwise.
no setter
-
removeWhiteSpaces
→ String?
-
Removes all whitespace characters (spaces) from the string.
no setter
-
startsWithNumber
→ bool
-
Checks if the string starts with a number (digit).
no setter
-
toDouble
→ double
-
Parses the string as a double or returns null if it is not a number.
no setter
-
toInt
→ int
-
Parses the string as an int or returns null if it is not a number.
no setter
-
toNum
→ num
-
Parses the string as a num or returns null if it is not a number.
no setter
-
toOneLine
→ String?
-
Converts the string into a single line by replacing newline characters.
no setter
-
tryToDouble
→ double?
-
Parses the string as a double or returns null if it is not a number.
no setter
-
tryToInt
→ int?
-
Parses the string as an int or returns null if it is not a number.
no setter
-
tryToNum
→ num?
-
Parses the string as a num or returns null if it is not a number.
no setter
Methods
-
anyChar(bool predicate(String element))
→ bool
-
Returns true if at least one character matches the given
predicate
.
The predicate
should have only one character.
-
decode({Object? reviver(Object? key, Object? value)?})
→ dynamic
-
Decodes the JSON string into a dynamic data structure.
Returns the decoded dynamic data structure if the string is non-empty and valid JSON.
Returns null if the string is null or empty, or if the string is not a valid JSON format.
-
equalsIgnoreCase(String? other)
→ bool
-
Compares the current string with another string for equality, ignoring case differences.
-
hasMatch(String pattern, {bool caseSensitive = true})
→ bool
-
-
ifEmpty<T>(Future<T> action())
→ Future<T>?
-
If the string is empty, performs an action.
-
insert(int index, String str)
→ String
-
Returns a new string in which a specified string is inserted at a specified index position in this instance.
-
limitFromEnd(int maxSize)
→ String?
-
Shrinks the string to be no more than
maxSize
in length, extending from the end.
Example: In a string with 10 characters, a maxSize
of 3 would return the last 3 characters.
-
limitFromStart(int maxSize)
→ String?
-
Shrinks the string to be no more than
maxSize
in length, extending from the start.
Example: In a string with 10 characters, a maxSize
of 3 would return the first 3 characters.
-
removeSurrounding(String delimiter)
→ String?
-
Returns the string only if the delimiter exists at both ends, otherwise returns the current string.
-
replaceAfter(String delimiter, String replacement, [String? defaultValue])
→ String?
-
Replaces part of the string after the first occurrence of the given delimiter with the
replacement
string.
If the string does not contain the delimiter, returns defaultValue
which defaults to the original string.
-
replaceBefore(String delimiter, String replacement, [String? defaultValue])
→ String?
-
Replaces part of the string before the first occurrence of the given delimiter with the
replacement
string.
If the string does not contain the delimiter, returns defaultValue
which defaults to the original string.
-
toCharArray()
→ List<String>
-
Returns a list of characters from the string.
-
wrapString({int wordCount = 1, bool wrapEach = false, String delimiter = '\n'})
→ String
-
Wraps the string based on the specified word count, wrap behavior, and delimiter.
Example: "This is a test".wrapString(wrapCount: 2, wrapEach: false) => "This is\na test"