FunctionalStringExtensions 1.0.5

dotnet add package FunctionalStringExtensions --version 1.0.5
                    
NuGet\Install-Package FunctionalStringExtensions -Version 1.0.5
                    
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="FunctionalStringExtensions" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FunctionalStringExtensions" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="FunctionalStringExtensions" />
                    
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 FunctionalStringExtensions --version 1.0.5
                    
#r "nuget: FunctionalStringExtensions, 1.0.5"
                    
#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.
#:package FunctionalStringExtensions@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FunctionalStringExtensions&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=FunctionalStringExtensions&version=1.0.5
                    
Install as a Cake Tool

🧶 FunctionalStringExtensions

FunctionalStringExtensions is a C# class library that provides a set of extension methods for working with strings. These extensions are designed to make common string manipulation tasks more convenient and expressive. Whether you're dealing with default values, asynchronous operations, or executing actions based on string conditions, these extensions aim to simplify your code and enhance its readability.

Installation 🚀

To easily integrate the FunctionalStringExtensions library into your project, you can use NuGet Package Manager. NuGet is a package manager for .NET that simplifies the process of adding, removing, and updating libraries in your applications.

After that import the FunctionalStringExtensions namespace in your code files where you want to use the provided extension methods:

using FunctionalStringExtensions;

Available Extension Methods 🛠️

OrDefault

This extension method returns the provided default value if the input string is null or empty.

Usage:

string result = input.OrDefault("default value");

OrDefaultAsync

Similar to the OrDefault method, this asynchronous extension returns a default value obtained from a Task<string> if the input string is null or empty.

Usage:

string result = await input.OrDefaultAsync(Task.FromResult("default value"));

WhenNullOrEmpty

This extension method returns the result of the provided delegate function if the input string is null or empty.

Usage:

string result = input.WhenNullOrEmpty(() => "default value");

WhenNullOrEmptyAsync

Similar to the WhenNullOrEmpty method, this asynchronous extension returns a value obtained from a Task<string> returned by the delegate function if the input string is null or empty.

Usage:

string result = await input.WhenNullOrEmptyAsync(async () => await GetDefaultValueAsync());

OnNullOrEmpty

This extension method executes the provided action if the input string is null or empty.

Usage:

input.OnNullOrEmpty(() => Console.WriteLine("Input is null or empty."));

OnNullOrEmptyAsync

Similar to the OnNullOrEmpty method, this asynchronous extension executes a provided task if the input string is null or empty.

Usage:

await input.OnNullOrEmptyAsync(async () => await PerformAsyncAction());

ToSlug

Turns your string in a slug

Usage

var slug = "ICH MUß EINIGE CRÈME BRÛLÉE HABEN".ToSlug();

ToEnum

Parse your string to a Enum value

Usage


public enum FakeEnum
{
    Value1,
    Value2
}

var result = "Value1".ToEnum<FakeEnum>(); // FakeEnum.Value1

OnlyLetters

Search for letters (A to Z) in the string

Usage

var result = "abc123def456ghi".OnlyLetters(); //"abcdefghi"

OnlyNumbers

Search for numbers (0 to 9) in the string

Usage

var result = "abc123def456ghi".OnlyNumbers(); //"123456"

OnlyCharactersAndNumbers

Search for characters and numbers (A to Z or 0 to 9) in the string

Usage

var result = "12.8/0';@#!%^&*()a12,9abc".OnlyCharactersAndNumbers(); //"1280a129abc"

OnlySpecialCharacters

Search for especial characters (not A to Z and not 0 to 9) in the string

Usage

var result = "12.8/0';@#!%^&*()a12,9abc".OnlySpecialCharacters(); //"./';@#!%^&*(),"

ParseQueryString

Parses a query string into a dictionary of key-value pairs.

Usage

var queryString = "?name=JohnDoe&age=30&isMember=true";
var result = queryString.ParseQueryString(autoConvertType: true);
// result will be a dictionary with keys "name", "age", "isMember"
// and corresponding values "JohnDoe", 30, true
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • 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.0.5 153 6/26/2024
1.0.4 125 6/13/2024
1.0.3 166 3/21/2024
1.0.2 275 1/31/2024
1.0.1 577 8/15/2023
1.0.0 563 8/11/2023