GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Antyss77/StringExtension: A C# library that provides utility methods for manipulating strings.

BranchesTags
Open more actions menu

Latest commit

 

History

54 Commits
54 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
Benchmarks
Benchmarks
 
 
StringExtension
StringExtension
 
 
UnitTests
UnitTests
 
 
.gitignore
.gitignore
 
 
Directory.Build.props
Directory.Build.props
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
StringExtension.slnx
StringExtension.slnx
 
 

Repository files navigation

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"

"[email protected]".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

  • Unit tests: UnitTests/StringExtensionTests.cs
  • Performance tests: Benchmarks/Benchmark.cs
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.

About

A C# library that provides utility methods for manipulating strings.

Topics

camelcasecasingcharacter-manipulationcshardotnetemail-validationextensionslibrarynugetpalindromephone-number-validationruneslugifystringstring-manipulationstring-processinsubstringtext-processingunicodeword-manipulation

Resources

Readme
MIT license
Activity

Stars

8 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.