FastEasy.StringExtensions
1.0.1
dotnet add package FastEasy.StringExtensions --version 1.0.1
NuGet\Install-Package FastEasy.StringExtensions -Version 1.0.1
<PackageReference Include="FastEasy.StringExtensions" Version="1.0.1" />
<PackageVersion Include="FastEasy.StringExtensions" Version="1.0.1" />
<PackageReference Include="FastEasy.StringExtensions" />
paket add FastEasy.StringExtensions --version 1.0.1
#r "nuget: FastEasy.StringExtensions, 1.0.1"
#addin nuget:?package=FastEasy.StringExtensions&version=1.0.1
#tool nuget:?package=FastEasy.StringExtensions&version=1.0.1
FastEasyStringExtensions
FastEasyStringExtensions is a clean, fast, and easy-to-use C# library providing a rich collection of extension methods for strings. Whether you're building web apps, APIs, or desktop tools, these helpers make working with text simpler, faster, and more expressive.
It addresses common string manipulation needs such as encoding, formatting, hashing, counting, and comparison, while keeping your code readable and free of boilerplate.
Features
Encoding & Decoding
Base64 encode/decode
URL encode/decode
HTML encode/decode
Date & Time Parsing
Parse strings into
DateTime
objects using flexible formatsConvert between
DateTime
and string representations easily
Advanced Text Comparison
LevenshteinDistance, CosineSimilarity, JaccardSimilarity and NGramSimilarity
Case-insensitive and culture-aware string comparison
Support for whitespace and special character handling
Methods for normalizing text before comparison (e.g., removing diacritics, collapsing spaces and whites spaces)
Text Manipulation
Collapse duplicate characters or whitespaces
Trim, normalize, and reformat strings
Counting Utilities
- Count words, count distinct words, lines, characters, or specific substrings
Hash Generators
- Generate CRC32, MD5, SHA1, SHA256, and SHA512 hashes from strings
Web Utilities
Encode/decode strings for safe use in web contexts (URLs, HTML)
Usefull when storing text in databases++
Installation
Install via NuGet Package Manager:
Install-Package FastEasyStringExtensions
Or via .NET CLI:
dotnet add package FastEasyStringExtensions
Example Usage
using StringExtensions;
// Example 1: Check if a string is null or empty
string emptyString = "";
bool isEmpty = emptyString.IsNullOrEmpty(); // true
// Example 2: Check if a string is null, empty, or whitespace
string whitespaceString = " ";
bool isWhitespace = whitespaceString.IsNullOrWhiteSpace(); // true
// Example 3: Remove diacritics (accents) from a string
string stringWithDiacritics = "Café";
string withoutDiacritics = stringWithDiacritics.RemoveDiacritics(); // "Cafe"
// Example 4: Remove the last character from a string if it matches the specified character
string stringWithComma = "Hello,";
string withoutComma = stringWithComma.RemoveLastCharacterIf(','); // "Hello"
// Example 5: Safely extract a substring from the given string
string longString = "Hello, World!";
string safeSubstring = longString.SubstringSafe(7, 5); // "World"
// Example 6: Convert a string to a boolean with a usefull range of true indicators
string boolString = "true"; // or "True", "TRUE", "1", "yes", "YES", "y", "Y", "on", "ON"
bool boolValue = boolString.ToBoolOrDefault(); // true
// Example 7: Base64 encode/decode
string original = "Hello World!";
string base64 = original.EncodeBase64(); // Base64 encode
string decoded = base64.DecodeBase64(); // Base64 decode
// Example 8: URL encode/decode
string urlSafe = original.EncodeUrl(); // URL encode
string clean = urlSafe.DecodeUrl(); // URL decode
// Example 9: Collapse multiple spaces to a single space
string textWithSpaces = "This is a test.";
string collapsedSpaces = textWithSpaces.CollapseSpaces(); // "This is a test."
// Example 10: Collapse multiple tabs to a single tab
string textWithTabs = "This\t\tis\t\ta\t\ttest.";
string collapsedTabs = textWithTabs.CollapseTabs(); // "This\tis\ta\ttest."
// Example 11: Collapse line endings to a single line ending
string textWithLineEndings = "Line1\r\n\r\nLine2\n\nLine3\r\rLine4";
string collapsedLineEndings = textWithLineEndings.CollapseLineEndings(); // "Line1\r\nLine2\r\nLine3\r\nLine4"
// Example 12: Count the number of words in a string
int wordCount = "This is a test.".CountWords(); // 4
// Example 13: Check if a string is numeric
bool isNumeric = "12345".IsNumeric(); // true
bool isNotNumeric = "12345abc".IsNumeric(); // false
// Example 14: Check if a string contains only letters
bool isLettersOnly = "HelloWorld".IsLettersOnly(); // true
bool isNotLettersOnly = "Hello123".IsLettersOnly(); // false
// Example 15: Convert a string to a DateTime, with a LONG range of date formats are supported.
string dateString = "2023-01-03";
DateTime date = dateString.ToDateTime(); // DateTime object representing January 3, 2023
// Example 16: Compute the SHA256 hash of a string (most past and present hashes are included)
string hashed = "myPassword".HashSHA256(); // SHA256 hash of "myPassword"
// Example 17: Determine whether the input string is a valid absolute URL
string urlString = "https://www.example.com";
bool isValidUrl = urlString.IsUrl(); // true
// Example 18: Validate if the string is a well-formed email address
string emailString = "test@example.com";
bool isValidEmail = emailString.IsEmailAddress(); // true
// Example 19: Calculate similarity in large (or small) texts using advanced methods (Levenshtein distance (normalized and absolute), CosineSimilarity, JaccardSimilarity and NGramSimilarity.
string test1 = "kitten";
string text2 = "sitting";
double levenshteinDistance = text1.CompareLevenshteinDistanceAbsolute(text2); // 3
// Example 20: Compare the Jaccard similarity between two strings
string string3 = "beautiful night sky";
string string4 = "perfect night sky";
double jaccardSimilarity = string3.CompareJaccardSimilarity(string4); // 0.5
Method Summary (by category and file order)
Collapse.cs
CollapseSpaces: Collapse methods
CollapseTabs: Collapse tabs to a single tab
CollapseLineEndings: Precompiled regex for better performance
CollapseLineEndings: Remove multiple empty lines, replacing them with a single line.
CollapseWhitespaces: Whitespace lookup table
CollapseRepeatedChar: Collapse repeated characters to a single character
Common.cs
TrimPlus: Common methods
SubstringSafe: Safely extracts a substring from the given string.
TruncateSafe: Set max length of string
RemoveLastCharacterIf: Remove the last character from a string if it matches the specified character.
Reverse: Reverses the characters in the string.
RemoveDiacritics: Removes all diacritics (accents) from the string
CompareText.cs
CompareLevenshteinDistanceAbsolute: Methods for advanced string comparison.
CompareLevenshteinDistanceNormalized: Returns the normalized Levenshtein distance between two strings.
CompareCosineSimilarity: Returns the cosine similarity between two strings.
CompareJaccardSimilarity: Returns the Jaccard similarity between two strings.
CompareNGramSimilarity: Returns the NGram similarity between two strings.
ConversionDateTime.cs
ToDateTime: Converts a string to a DateTime using a variety of supported formats:
yyyy-MM-dd
yyyy/MM/dd
dd-MM-yyyy
dd/MM/yyyy
yyyy-MM-dd HH:mm:ss
yyyy/MM/dd HH:mm:ss
MM-dd-yyyy
MM/dd/yyyy
yyyyMMdd
yyyyMMddHHmmss
ddMMyyyy
ddMMyyyyHHmmss
RFC1123 (e.g., Tue, 03 Jan 2023 08:00:00 GMT)
ISO 8601 (e.g., 2023-01-03T08:00:00Z)
All supported built in .Net formats
Count.cs
CountWords: Count methods
CountWordsDistinct: Count the number of distinct words in a string.
CountLines: Count the number of whitespace characters in a string.
CountWhitespaces: Count the number of whitespace characters in a string.
CountLetters: Count the number of alphabetic characters in a string.
CountDigits: Count the number of digit characters in a string.
CountOccurrences: Counts the number of occurrences of a given string in another.
CountOccurrences: Count the number of occurrences of a given character in a string.
Hashes.cs
HashCRC32: Computes the CRC32 hash of the given string and returns it as a hexadecimal string.
HashMD5: Computes the MD5 hash of the given string and returns it as a hexadecimal string.
HashSHA1: Computes the SHA1 hash of the given string and returns it as a hexadecimal string.
HashSHA256: Computes the SHA256 hash of the given string and returns it as a hexadecimal string.
HashSHA512: Computes the SHA512 hash of the given string and returns it as a hexadecimal string.
IsTest.cs
IsNullOrEmpty: Common string extension methods (fluent syntax).
IsNullOrWhiteSpace: Check if a string is null, empty, or whitespace (fluent syntax).
IsNumeric: Check if a string is numeric.
IsLettersOnly: True if ONLY LETTERS are present in the string.
IsDigitsOnly: True if the string contains only digits.
IsUrl: Determines whether the input string is a valid absolute URL
IsEmailAddress: Validates if the string is a well-formed email address.
NumericTypeConversion.cs
ToBoolOrDefault: Numeric type conversion methods.
ToShortOrDefault: Converts a string to a Short (int16).
ToIntOrDefault: Converts a string to an integer (int32).
ToLongOrDefault: Converts a string to a long (int64).
ToFloatOrDefault: Converts a string to a float.
ToDoubleOrDefault: Converts a string to a double.
ToDecimalOrDefault: Converts a string to a decimal.
Web.cs
EncodeBase64: Methods typically used for web-related tasks.
DecodeBase64: Convert Base64 to string.
EncodeUrl: URL encode a string.
DecodeUrl: URL decode a string.
EncodeHtml: HTML encode a string.
DecodeHtml: HTML decode a string.
Compatibility
Method Summary (by category and file order)
Collapse.cs
CollapseSpaces: Collapse multiple space characters to a single space character.
CollapseTabs: Collapse multiple tab characters to a single tab character.
CollapseLineEndings: Collapse line endings to a single line ending. All line endings are handled correctly: \r\n, \n, \r.
CollapseWhitespaces: Collapse all whitespace characters to a single space character. Multiple spaces are collapsed to a single space.
CollapseRepeatedChar: The entire string is scanned for multiple consecutive occurrences of the target character, and they are collapsed to a single occurrence.
CollapseRepeatedString: The entire string is scanned for multiple consecutive occurrences of the target string, and they are collapsed to a single occurrence.
Count.cs
CountWords: Count the number of words in a string.
CountWordsDistinct: Count the number of distinct words in a string.
CountLines: Count the number of lines in a string.
CountWhitespaces: Count the number of whitespace characters in a string.
IsTest.cs
IsNullOrEmpty: Check if a string is null or empty. Enables fluent syntax.
IsNullOrWhiteSpace: Check if a string is null, empty, or whitespace. Enables fluent syntax.
IsNumeric: Check if a string is numeric.
IsLettersOnly: True if ONLY LETTERS are present in the string.
IsDigitsOnly: True if the string contains only digits.
IsUrl: Determines whether the input string is a valid absolute URL.
IsEmailAddress: Validates if the string is a well-formed email address.
Web.cs
EncodeBase64: Convert a string to Base64. If the input is null or empty, the input is returned.
DecodeBase64: Convert Base64 to string. If the string is null, empty, or cannot be converted, the input is returned.
EncodeUrl: URL encode a string. If the input is null or empty, the input is returned.
DecodeUrl: URL decode a string. If the input is null or empty, the input is returned.
EncodeHtml: HTML encode a string. If the input is null or empty, the input is returned.
DecodeHtml: HTML decode a string. If the input is null or empty, the input is returned.
Compatibility
- .NET 9.0
- Fully compatible with ASP.NET, WPF, Blazor, and Console applications
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions
Feel free to open issues, submit pull requests, or suggest features. Contributions are welcome!
Related Tags
string, extensions, string-utils, hashing, encoding, dotnet, utilities, fluent syntax C#, helper-methods
.NET Standard 2.0+
.NET 5, 6, 7, 8, 9
Fully compatible with ASP.NET, WPF, Blazor, and Console applications
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions
Feel free to open issues, submit pull requests, or suggest features. Contributions are welcome!
Related Tags
string, extensions, string-utils, hashing, encoding, dotnet, utilities, fluent syntax C#, helper-methods
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
This is the initial release