# Dart String Utility Library
A collection of string manipulation utilities in Dart, providing various useful methods to enhance developer productivity by simplifying common string operations.
## Table of Contents
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Methods](#methods)
- [Contributing](#contributing)
- [License](#license)
- [Acknowledgments](#acknowledgments)
## Features
- Convert HTML special characters to plain text.
- Remove decimal zero from numeric strings.
- Convert strings to integers and doubles.
- Capitalize first letters or entire sentences.
- Convert strings to snake case and kebab case.
- Check for substring presence, ignoring case.
- Format dates from string or DateTime objects.
## Installation
To use this library, add it to your project's `pubspec.yaml`:
```yaml
dependencies:
your_library_name: ^0.0.1
Then run:
flutter pub get
Usage
Import the library in your Dart code:
import 'package:your_library_name/your_library_name.dart';
Example Usage
Here's an example of how to use some of the features:
import 'package:your_library_name/your_library_name.dart';
void main() {
String htmlString = "Tom & Jerry © 2024";
String plainText = htmlString.convertHtmlEntities(); // "Tom & Jerry © 2024"
String numberString = "45.0";
String formattedNumber = numberString.removeDecimalZero(); // "45"
String dateString = "2024-10-08";
String formattedDate = dateString.formatToCustomDate(
inputFormat: "yyyy-MM-dd",
outputFormat: "dd/MM/yyyy"
); // "08/10/2024"
}
Methods
HTML Entity Conversion
- Method:
String convertHtmlEntities() - Description: Converts HTML special characters into plain text.
Remove Decimal Zero
- Method:
String removeDecimalZero() - Description: Removes the decimal part if the string represents an integer.
Convert to Integer
- Method:
int? toInt() - Description: Converts the string to an integer. Returns
0if parsing fails.
Convert to Double
- Method:
double? toDouble() - Description: Converts the string to a double. Returns
0.0if parsing fails.
Capitalize First Letter
- Method:
String toCapitalize() - Description: Capitalizes the first letter of the string.
Capitalize Each Word
- Method:
String toCapitalizeSentence() - Description: Capitalizes the first letter of each word.
Convert to Snake Case
- Method:
String toSnakeCase() - Description: Converts spaces to underscores and lowercases the string.
Convert to Kebab Case
- Method:
String toKebabCase() - Description: Converts spaces to hyphens and lowercases the string.
Contains Ignoring Case
- Method:
bool containsIgnoreCase(String str) - Description: Checks if the string contains a specified substring, ignoring case.
Additional Extensions
- Zero Appender: Appends a zero to single-digit integers.
- Custom Date Formatting: Formats dates from a string or
DateTimeobject.
Contributing
Contributions are welcome! Please feel free to submit issues, fork the repository, and make pull requests.
License
This library is licensed under the MIT License. See the LICENSE file for more information.
Acknowledgments