Gapotchenko.FX.Text 2022.2.7

The ID prefix of this package has been reserved for one of the owners of this package by Prefix Reserved
.NET 5.0 .NET Core 2.0 .NET Standard 2.0 .NET Framework 4.6
dotnet add package Gapotchenko.FX.Text --version 2022.2.7
NuGet\Install-Package Gapotchenko.FX.Text -Version 2022.2.7
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="Gapotchenko.FX.Text" Version="2022.2.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gapotchenko.FX.Text --version 2022.2.7
#r "nuget: Gapotchenko.FX.Text, 2022.2.7"
#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.
// Install Gapotchenko.FX.Text as a Cake Addin
#addin nuget:?package=Gapotchenko.FX.Text&version=2022.2.7

// Install Gapotchenko.FX.Text as a Cake Tool
#tool nuget:?package=Gapotchenko.FX.Text&version=2022.2.7


The module provides primitives for string and text manipulation.


StringEditor class provided by Gapotchenko.FX.Text module allows to perform an iterative random-access editing of a string.

It is primarily designed to work in conjunction with Regex class from System.Text.RegularExpressions namespace to efficiently handle an advanced set of tasks when functionality provided by conventional methods like Regex.Replace is just not enough.

More on StringEditor class

Regular Expression Trampolines

Regex trampolines are special functions that allow to gradually convert the conventional string manipulation code into one that uses regex semantics.

Let's take a look on example:

if (name.Equals("[mscorlib]System.Object", StringComparison.Ordinal))
    Console.WriteLine("The name represents a system object.");

The given code is later changed in order to cover the new requirements:

if (name.Equals("[mscorlib]System.Object", StringComparison.Ordinal) ||
    name.Equals("[netstandard]System.Object", StringComparison.Ordinal) ||
    name.Equals("[System.Runtime]System.Object", StringComparison.Ordinal))
    Console.WriteLine("The name represents a system object.");

It does the job but such mechanical changes may put a toll on code maintainability when they accumulate. You can also spot some amount of code duplication here.

Another approach would be to use Regex class which is readily available in .NET. But that might destroy the expressiveness of string manipulation functions like Equals. If a string function takes a StringComparison parameter then it may become a significant challenge to reliably refactor it to Regex implementation.

That's why Gapotchenko.FX.Text module provides a set of so called regex trampoline functions. They look exactly like Equals, StartsWith, EndsWith, IndexOf but work with regex patterns instead of raw strings. They also end with Regex suffix in their names, so Equals becomes EqualsRegex, StartsWith correspondingly becomes StartsWithRegex, and so on.

And this is how a regex trampoline can be used for the given sample in order to meet the new requirements by a single line change:

using Gapotchenko.FX.Text.RegularExpressions;

if (name.EqualsRegex(@"\[(mscorlib|netstandard|System\.Runtime)]System\.Object", StringComparison.Ordinal))
    Console.WriteLine("The name represents a system object.");

An immediate improvement in expressiveness without duplication.

StringBuilder Polyfills


StringBuilder.AppendJoin is a method that appeared in later versions of .NET platform. Gapochenko.FX provides a corresponding polyfill that can be used in code targeting older .NET versions.

The benefit of this method is that it combines string.Join and StringBuilder.Append operations into one method using the underlying efficiency of StringBuilder.

Commonly Used Types

  • Gapotchenko.FX.Text.StringEditor

Other Modules

Let's continue with a look at some other modules provided by Gapotchenko.FX:

Or look at the full list of modules.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 is compatible.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Gapotchenko.FX.Text:

Package Downloads
Gapotchenko.FX.Diagnostics.CommandLine The ID prefix of this package has been reserved for one of the owners of this package by

The module provides primitives for command line manipulation.

Gapotchenko.FX.IO The ID prefix of this package has been reserved for one of the owners of this package by

The module provides highly demanded input/output functionality that is missing in conventional .NET platform.

Gapotchenko.FX.Profiles.Core The ID prefix of this package has been reserved for one of the owners of this package by

Represents the Core profile of Gapotchenko.FX.

Gapotchenko.FX.Console The ID prefix of this package has been reserved for one of the owners of this package by

The module provides virtual terminal functionality, console traits and useful primitives for .NET console apps.

Gapotchenko.FX.Data.Encoding.Base32 The ID prefix of this package has been reserved for one of the owners of this package by

The module provides the implementation of data encoding algorithms belonging to Base32 family: Base32, base32-hex, Crockford Base 32, z-base-32.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2022.2.7 17,833 5/1/2022
2022.2.5 1,953 5/1/2022
2022.1.4 1,675 4/6/2022
2021.2.21 1,687 1/21/2022
2021.2.20 1,688 1/17/2022
2021.1.5 1,054 7/6/2021
2020.2.2-beta 563 11/21/2020
2020.1.15 1,236 11/5/2020
2020.1.9-beta 640 7/14/2020
2020.1.8-beta 618 7/14/2020
2020.1.7-beta 662 7/14/2020
2020.1.1-beta 787 2/11/2020
2019.3.7 1,132 11/4/2019
2019.2.20 1,089 8/13/2019
2019.1.151 1,234 3/30/2019