StringExtensions extension
Extensions for presentation, like adding quotes, truncating text, and formatting.
- on
Properties
- hasInvalidUnicode → bool
-
Available on String, provided by the StringExtensions extension
Returns true if this string contains invalid Unicode characters.no setter - reversed → String
-
Available on String, provided by the StringExtensions extension
Reverses the characters in the string. Handles Unicode characters correctly.no setter
Methods
-
appendNotEmpty(
String value) → String -
Available on String, provided by the StringExtensions extension
Appendsvalueonly if this string is not empty. -
collapseMultilineString(
{required int cropLength, bool appendEllipsis = true}) → String -
Available on String, provided by the StringExtensions extension
Collapses a multiline string into a single line with optional truncation. -
compressSpaces(
{bool trim = true}) → String? -
Available on String, provided by the StringExtensions extension
Extension method to remove consecutive spaces in a String and optionally trim the result. This is an alias for removeConsecutiveSpaces. -
containsIgnoreCase(
String? other) → bool -
Available on String, provided by the StringExtensions extension
Checks if this string containsotherin a case-insensitive manner. -
count(
String find) → int -
Available on String, provided by the StringExtensions extension
Counts occurrences offindin this string. -
encloseInParentheses(
{bool wrapEmpty = false}) → String? -
Available on String, provided by the StringExtensions extension
Extension method to enclose a String in parentheses. -
endsWithAny(
List< String> find) → bool -
Available on String, provided by the StringExtensions extension
Returns true if this string ends with any character infind. -
endsWithPunctuation(
) → bool -
Available on String, provided by the StringExtensions extension
Returns true if this string ends with punctuation. -
escapeForRegex(
) → String -
Available on String, provided by the StringExtensions extension
Escapes characters in a string that have a special meaning in regular expressions. -
extractCurlyBraces(
) → List< String> ? -
Available on String, provided by the StringExtensions extension
Extracts all text within curly braces from this string. -
firstLines(
int limit) → String -
Available on String, provided by the StringExtensions extension
Returns the firstlimitlines of this string. -
firstWord(
) → String? -
Available on String, provided by the StringExtensions extension
Returns the first word of this string. -
getEverythingAfter(
String find) → String -
Available on String, provided by the StringExtensions extension
Returns the substringSafe after the first occurrence offind. Returns the original string iffindis not found. -
getEverythingAfterLast(
String find) → String -
Available on String, provided by the StringExtensions extension
Returns the substringSafe after the last occurrence offind. Returns the original string iffindis not found. -
getEverythingBefore(
String find) → String -
Available on String, provided by the StringExtensions extension
Returns the substringSafe before the first occurrence offind. Returns the original string iffindis not found. -
getFirstDiffChar(
String other) → String -
Available on String, provided by the StringExtensions extension
-
getRandomChar(
) → String -
Available on String, provided by the StringExtensions extension
Returns a random character from this string. -
grammarArticle(
) → String -
Available on String, provided by the StringExtensions extension
Returns the appropriate indefinite article ('a' or 'an') for this word. -
hasAnyDigits(
) → bool -
Available on String, provided by the StringExtensions extension
Returns true if this string contains any digit characters. -
insert(
String newChar, int position) → String -
Available on String, provided by the StringExtensions extension
InsertsnewCharat the specifiedposition. -
insertNewLineBeforeBrackets(
) → String -
Available on String, provided by the StringExtensions extension
Inserts a newline character before each opening parenthesis. -
isAny(
List< String> list) → bool -
Available on String, provided by the StringExtensions extension
Returns true if this string equals any item inlist. -
isBracketWrapped(
) → bool -
Available on String, provided by the StringExtensions extension
Checks if the string starts and ends with matching brackets. e.g.,(abc),[abc],{abc},<abc>. -
isEquals(
String? other, {bool ignoreCase = true, bool normalizeApostrophe = true}) → bool -
Available on String, provided by the StringExtensions extension
Compares this string toother, with options for case-insensitivity and apostrophe normalization. -
isLatin(
) → bool -
Available on String, provided by the StringExtensions extension
Checks if the string contains only Latin alphabet characters (a-z, A-Z). -
isVowel(
) → bool -
Available on String, provided by the StringExtensions extension
Returns true if this single-character string is a vowel. -
last(
int len) → String -
Available on String, provided by the StringExtensions extension
Gets the lastlencharacters of this string, handling Unicode correctly. -
lastChars(
int n) → String -
Available on String, provided by the StringExtensions extension
Get the lastngraphemes (user-perceived characters) of a string. -
lettersOnly(
) → String -
Available on String, provided by the StringExtensions extension
Extracts only ASCII letter characters (A-Z, a-z) from this string. -
lowerCaseLettersOnly(
) → String -
Available on String, provided by the StringExtensions extension
Extracts only ASCII lowercase letter characters (a-z) from this string. -
makeNonBreaking(
) → String -
Available on String, provided by the StringExtensions extension
Replaces hyphens and spaces with non-breaking equivalents. -
multiLinePrefix(
String insertText, {bool prefixEmptyStrings = false}) → String -
Available on String, provided by the StringExtensions extension
Prefixes every line withinsertText. -
normalizeApostrophe(
) → String -
Available on String, provided by the StringExtensions extension
Replaces different apostrophe characters (’ and ') with a standard single quote. -
nullIfEmpty(
{bool trimFirst = true}) → String? -
Available on String, provided by the StringExtensions extension
Returnsnullif the string is empty or contains only whitespace. -
obscureText(
{String char = '•', int obscureLength = 3}) → String? -
Available on String, provided by the StringExtensions extension
Creates an obscured version of this string (e.g., for masking passwords). -
pluralize(
num? count, {bool simple = false}) → String -
Available on String, provided by the StringExtensions extension
Returns the plural form of this string. -
possess(
{bool isLocaleUS = true}) → String -
Available on String, provided by the StringExtensions extension
Returns the possessive form of this string (e.g., "John's", "boss'"). -
prefixNotEmpty(
String? value) → String -
Available on String, provided by the StringExtensions extension
Prependsvalueonly if this string is not empty. -
removeAll(
Pattern? pattern) → String -
Available on String, provided by the StringExtensions extension
Replaces all occurrences ofpatternwith an empty string. -
removeConsecutiveSpaces(
{bool trim = true}) → String? -
Available on String, provided by the StringExtensions extension
Extension method to remove consecutive spaces in a String and optionally trim the result. -
removeEnd(
String end) → String -
Available on String, provided by the StringExtensions extension
Removesendfrom the end of the string, if it exists. -
removeFirstChar(
) → String -
Available on String, provided by the StringExtensions extension
Removes the first character from the string. -
removeFirstLastChar(
) → String -
Available on String, provided by the StringExtensions extension
Removes both the first and the last character from the string. -
removeInvalidUnicode(
) → String -
Available on String, provided by the StringExtensions extension
Removes all invalid Unicode replacement characters. -
removeLastChar(
) → String -
Available on String, provided by the StringExtensions extension
Removes the last character from the string. -
removeLastOccurrence(
String target) → String -
Available on String, provided by the StringExtensions extension
Removes the last occurrence oftargetfrom the string. -
removeLeadingAndTrailing(
String? find, {bool trim = false}) → String? -
Available on String, provided by the StringExtensions extension
Removes leading and trailing occurrences offind. -
removeMatchingWrappingBrackets(
) → String -
Available on String, provided by the StringExtensions extension
Removes the first and last characters if they are a matching pair of brackets. -
removeNonAlphaNumeric(
{bool allowSpace = false}) → String -
Available on String, provided by the StringExtensions extension
Removes all characters that are not letters or numbers. -
removeNonNumbers(
) → String -
Available on String, provided by the StringExtensions extension
Removes all characters that are not digits (0-9). -
removeSingleCharacterWords(
{bool trim = true, bool removeMultipleSpaces = true}) → String? -
Available on String, provided by the StringExtensions extension
Removes single-character words (letters and digits) from this string. -
removeStart(
String? start, {bool isCaseSensitive = true, bool trimFirst = false}) → String? -
Available on String, provided by the StringExtensions extension
Returns a new string with the specifiedstartremoved from the beginning of the original string, if it exists. -
removeWrappingChar(
String char, {bool trimFirst = true}) → String -
Available on String, provided by the StringExtensions extension
Removes the specifiedcharfrom the beginning and/or end of the string. -
repeat(
int count) → String -
Available on String, provided by the StringExtensions extension
Repeats this stringcounttimes. -
replaceLastNCharacters(
int n, String replacementChar) → String -
Available on String, provided by the StringExtensions extension
Replaces the lastncharacters withreplacementChar. -
replaceLineBreaks(
String? replacement, {bool deduplicate = true}) → String -
Available on String, provided by the StringExtensions extension
Replaces all line breaks (\n) with a specified string. -
replaceNonNumbers(
{String replacement = ''}) → String -
Available on String, provided by the StringExtensions extension
Replaces all characters that are not digits (0-9) with thereplacementstring. -
secondIndex(
String char) → int -
Available on String, provided by the StringExtensions extension
Finds the index of the second occurrence ofchar. -
secondWord(
) → String? -
Available on String, provided by the StringExtensions extension
Returns the second word of this string. -
splitCapitalizedUnicode(
{bool splitNumbers = false, bool splitBySpace = false, int minLength = 1}) → List< String> -
Available on String, provided by the StringExtensions extension
Splits a string by capitalized letters (Unicode-aware) and optionally by spaces, with an option to prevent splits that result in short segments. -
substringSafe(
int start, [int? end]) → String -
Available on String, provided by the StringExtensions extension
Safely gets a substring, preventing RangeError. -
toAlphaOnly(
{bool allowSpace = false}) → String -
Available on String, provided by the StringExtensions extension
Removes all characters that are not letters (A-Z, a-z). -
trimLines(
) → String -
Available on String, provided by the StringExtensions extension
Trims each line and removes empty lines. -
trimWithEllipsis(
{int minLength = 5}) → String -
Available on String, provided by the StringExtensions extension
Truncates with ellipsis at both ends. -
truncateWithEllipsis(
int? cutoff) → String -
Available on String, provided by the StringExtensions extension
Truncates the string tocutoffgraphemes and appends an ellipsis '…'. -
truncateWithEllipsisPreserveWords(
int? cutoff) → String -
Available on String, provided by the StringExtensions extension
Truncates the string tocutoffgraphemes and appends an ellipsis '…'. -
words(
) → List< String> ? -
Available on String, provided by the StringExtensions extension
Splits the string into a list of words, using space (" ") as the delimiter. -
wrap(
{String? before, String? after}) → String -
Available on String, provided by the StringExtensions extension
Wraps the string with the givenbeforeandafterstrings. -
wrapDoubleAccentedQuotes(
{bool quoteEmpty = false}) → String -
Available on String, provided by the StringExtensions extension
Return a string wrapped in “accented quotes” -
wrapDoubleQuotes(
{bool quoteEmpty = false}) → String -
Available on String, provided by the StringExtensions extension
Wraps the string in double quotes:"string". -
wrapSingleAccentedQuotes(
{bool quoteEmpty = false}) → String -
Available on String, provided by the StringExtensions extension
Return a string wrapped in ‘accented quotes’ -
wrapSingleQuotes(
{bool quoteEmpty = false}) → String -
Available on String, provided by the StringExtensions extension
Wraps the string in single quotes:'string'. -
wrapWith(
{String? before, String? after}) → String? -
Available on String, provided by the StringExtensions extension
Extension method to wrap a String with a prefixbeforeand a suffixafter. Returns null if the string is empty.
Constants
- accentedDoubleQuoteClosing → const String
- accentedDoubleQuoteOpening → const String
- accentedQuoteClosing → const String
- accentedQuoteOpening → const String
- apostrophe → const String
- blank → const String
- bullet → const String
- Bullet point character (•).
-
commonWordEndings
→ const List<
String> - Common word-ending characters for text processing.
- dot → const String
- Alias for bullet.
- dotJoiner → const String
- A dot with spaces for joining items (e.g., "Item 1 • Item 2").
- doubleChevron → const String
- ellipsis → const String
- hyphen → const String
- lineBreak → const String
- newLine → const String
- nonBreakingHyphen → const String
- For not breaking words into newline at hyphen in Text
- nonBreakingSpace → const String
- softHyphen → const String
- Soft Hyphen character (U+00AD). Insert into strings to suggest word break points for automatic hyphenation by Flutter's text rendering engine. It's invisible unless a break occurs at its position.
- zeroWidth → const String
- 'This\u200Bis\u200Ba\u200Bsentence\u200Bwith\u200Bzero-width\u200Bspaces.