string_utilities

Creator: coderz1093

Last updated:

0 purchases

string_utilities Image
string_utilities Images

Languages

Categories

Add to Cart

Description:

string utilities

String Utility #
String Utility is a Dart package that provides a collection of useful extension methods for
working with strings in Dart and Flutter. The package includes functions for trimming, capitalizing,
reversing, retrieving words, and more.
Features #

ifEmpty: Returns a default value if a string is empty.
isBlank: Checks if a string is blank (empty or contains only whitespace).
toCapitalize: Capitalizes the first letter of a string.
toReverse: Reverses the characters in a string.
toLowerCase: Converts a string to lowercase.
toCapitalizeEachWord: Capitalizes the first letter of each word in a string.
removeLastWord: Removes the last word from a string.
getLastWord: Retrieves the last word from a string.
isEquals: Compares two strings with optional case-insensitive comparison and trimming.

Getting Started #
To use this package in your Flutter or Dart project, add the following dependency to
your pubspec.yaml file:
dependencies:
string_utility: ^1.0.0
copied to clipboard
Usage #
ifEmpty Example #
The ifEmpty method returns a default value if the string is empty; otherwise, it returns the
original string.

String name = "John Doe".ifEmpty("Unknown");

print(name); // Output: "John"
copied to clipboard
isBlank Example #
The isBlank method returning true if it is empty or contains only whitespace, and false
otherwise.

bool isBlank = " ".isBlank(); // true
bool isNotBlank = "Text".isBlank(); // false
copied to clipboard
toCapitalize Example #
The toCapitalize method check if the string is empty, it returns the original string.Otherwise, it
converts the first character to uppercase and appends the rest of the string.

String capitalized = "hello".toCapitalize(); // "Hello"
copied to clipboard
toReverse Example #
The toReverse method splits the string into individual characters, reverses the order, and joins
them back into a single string.

String reversed = "Flutter".toReverse(); // "rettulF"
copied to clipboard
toLowerCase Example #
The toLowerCase method return all converted characters in the string to lowercase.

String lowerCase = "HELLO WORLD".toLowerCase(); // "hello world"
copied to clipboard
toCapitalizeEachWord Example #
The toCapitalizeEachWord method splits the string by spaces and capitalizes the first letter of
each word.

String capitalizedWords = "make each word capitalized"
.toCapitalizeEachWord(); // "Make Each Word Capitalized"
copied to clipboard
removeLastWord Example #
The removeLastWord method splits the string by whitespace, removes the last word, and then joins
the remaining words into a new string.If the string has only one word or is empty, then result is an
empty string.

String result = "This is a sentence.".removeLastWord();

print(result); // Output: "This is a"
copied to clipboard
getLastWord Example #
The getLastWord method splits the string by whitespace and retrieves the last word.If the string
is empty or has no words, it returns an empty string.

String lastWord = "This is a sentence.".getLastWord();

print(lastWord); // Output: "sentence."
copied to clipboard
isEquals Example #
The isEquals method returns true if the current string is equivalent to other based on the
given flags.

bool caseInsensitiveEqual = "hello".isEquals("HELLO", ignoreCase: true); // true
bool trimmedEqual = " hello ".isEquals("hello", trim: true); // true
bool caseSensitiveEqual = "hello".isEquals("HELLO"); // false
bool bothEqual = " hello ".isEquals("HELLO", ignoreCase: true, trim: true); // true
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.