FastEasy.StringExtensions 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package FastEasy.StringExtensions --version 1.0.0
                    
NuGet\Install-Package FastEasy.StringExtensions -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FastEasy.StringExtensions" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FastEasy.StringExtensions" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FastEasy.StringExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FastEasy.StringExtensions --version 1.0.0
                    
#r "nuget: FastEasy.StringExtensions, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=FastEasy.StringExtensions&version=1.0.0
                    
Install FastEasy.StringExtensions as a Cake Addin
#tool nuget:?package=FastEasy.StringExtensions&version=1.0.0
                    
Install FastEasy.StringExtensions as a Cake Tool

FastEasyStringExtensions

NuGet version

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 formats

    • Convert between DateTime and string representations easily

  • Text Comparison

    • Case-insensitive and culture-aware string comparison

    • Support for whitespace and special character handling

  • Text Manipulation

    • Collapse duplicate characters or whitespaces

    • Trim, normalize, and reformat strings

  • Counting Utilities

    • Count words, lines, characters, or specific substrings
  • Hash Generators

    • Generate MD5, SHA1, SHA256, and SHA512 hashes from strings
  • Web Utilities

    • Encode/decode strings for safe use in web contexts (URLs, HTML)

Installation

Install via NuGet Package Manager:

Install-Package FastEasyStringExtensions

Or via .NET CLI:

dotnet add package FastEasyStringExtensions


Example Usage

using StringExtensions;

string original = "Hello World!";

string base64 = original.EncodeBase64(); // Base64 encode
string decoded = base64.DecodeBase64();  // Base64 decode

string urlSafe = original.EncodeUrl();   // URL encode
string clean = urlSafe.DecodeUrl();      // URL decode

int wordCount = "This is a test.".CountWords();
string hashed = "myPassword".ToSha256();


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)

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

  • .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!


string, extensions, string-utils, hashing, encoding, dotnet, utilities, fluent syntax C#, helper-methods

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
1.1.0 50 a day ago
1.0.2 112 2 days ago
1.0.1 167 11 days ago
1.0.0 147 12 days ago

This is the initial release