You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

Gapotchenko.FX.Text

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Gapotchenko.FX.Text

Provides primitives for string and text manipulation.

2025.1.25-beta
nugetNuGet
Version published
Maintainers
1
Created
Source

Overview

The module provides primitives for string and text manipulation.

StringEditor

StringEditor class provided by Gapotchenko.FX.Text module allows you 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

AppendJoin

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 in one method, while using the underlying efficiency of the 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.

Keywords

framework

FAQs

Package last updated on 22 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts