String-Extension 2.3.0

dotnet add package String-Extension --version 2.3.0
                    
NuGet\Install-Package String-Extension -Version 2.3.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="String-Extension" Version="2.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="String-Extension" Version="2.3.0" />
                    
Directory.Packages.props
<PackageReference Include="String-Extension" />
                    
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 String-Extension --version 2.3.0
                    
#r "nuget: String-Extension, 2.3.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.
#:package String-Extension@2.3.0
                    
#: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=String-Extension&version=2.3.0
                    
Install as a Cake Addin
#tool nuget:?package=String-Extension&version=2.3.0
                    
Install as a Cake Tool

StringExtension

NuGet Version NuGet Downloads License: MIT .NET

A string manipulation library for C#, built around three principles: correctness, performance, and a minimal API surface.

  • Zero-allocation where possible. Most methods operate on Span<char>/ReadOnlySpan<char> internally, using stackalloc for small inputs and ArrayPool<char> for larger ones instead of allocating a new array on every call.
  • Unicode-correct. Methods that classify or compare characters operate on whole Unicode scalar values (via Rune) rather than raw UTF-16 code units, so characters outside the Basic Multilingual Plane (many emoji, some rare scripts) are handled correctly instead of being split into invalid half-characters.
  • Both string and ReadOnlySpan<char> overloads. Every method that accepts a string also has a ReadOnlySpan<char> overload, so you can call it on a slice without allocating an intermediate string.

Requirements

.NET 10.0 or later.

Installation

dotnet add package String-Extension

API

Methods are split across namespaces by category. Add the relevant using statement for the methods you need.

using StringExtension;

General-purpose string manipulation.

Method Description
RemoveCharacters(char[]) Removes the specified characters from a string.
CountSubstring(string) Counts the number of occurrences of a substring.
ReverseWords() Reverses the order of words in a string.
RemoveDuplicateCharacters() Removes duplicate characters, keeping the first occurrence of each.

using StringExtension.Validation;

Format validation.

Method Description
IsValidEmail() Validates an e-mail address.
IsValidPhoneNumber() Validates a phone number.

using StringExtension.Linguistics;

Text analysis.

Method Description
IsPalindrome() Determines if a string is a palindrome.
CountLetters() Counts the number of letters in a string.

using StringExtension.Casing;

Casing conventions and slug generation.

Method Description
ToCamelCase() Converts to camelCase.
ToPascalCase() Converts to PascalCase.
ToSnakeCase() Converts to snake_case.
ToKebabCase() Converts to kebab-case.
ToTitleCase(bool) Converts to Title Case, with an optional flag to keep short English words (of, the, and, ...) lowercase.
Slugify(char) Converts to a URL-friendly slug, stripping accents and collapsing punctuation into a single separator.

Examples

using StringExtension;
using StringExtension.Casing;
using StringExtension.Linguistics;
using StringExtension.Validation;

"hello world!".RemoveCharacters(['l', 'o']);   // "he wrd!"
"hello world!".ReverseWords();                 // "world! hello"

"john.doe@example.com".IsValidEmail();         // true
"racecar".IsPalindrome();                      // true

"hello_world".ToCamelCase();                   // "helloWorld"
"helloWorld".ToSnakeCase();                    // "hello_world"
"the lord of the rings".ToTitleCase(useEnglishMinorWordRules: true);
                                                // "The Lord of the Rings"
"Café de la Gare! 2024".Slugify();             // "cafe-de-la-gare-2024"

Performance

Every method that returns a string avoids unnecessary intermediate allocations. As an example, here is the impact of the zero-allocation rewrite of a few methods (measured with BenchmarkDotNet on identical hardware, before and after):

Method Before After Allocated (before → after)
IsPalindrome 466 ns 1.6 ns 648 B → 0 B
CountSubstring 59 ns 1.6 ns 40 B → 0 B
CountLetters 101 ns 3.7 ns 32 B → 0 B

Run the benchmarks yourself:

dotnet run -c Release --project Benchmarks/Benchmarks.csproj

Tests

dotnet test

Contributing

Contributions are welcome, whether that's proposing new methods, reporting bugs, or improving existing code. Open a Pull Request and it will be reviewed.

License

Distributed under the MIT License. See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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
2.3.0 87 8/13/2026
2.2.0 86 8/9/2026
2.1.0 90 8/9/2026
2.0.0 91 8/8/2026
1.5.7 88 8/8/2026
1.5.6 88 8/6/2026
1.5.5 91 8/5/2026
1.5.4 84 8/5/2026
1.5.1 366 4/14/2023