Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

847 Commits
847 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NetEvolve.Extensions.Strings

NuGet NuGet Downloads License

A modern .NET library providing essential extension methods for System.String to simplify common string operations. Part of the Daily DevOps & .NET - NetEvolve project.

Features

  • 🎯 Simple & Intuitive API - Extension methods that feel natural to use
  • 🚀 Multi-Framework Support - Compatible with .NET Standard 2.0, .NET 8.0, .NET 9.0, and .NET 10.0
  • 📦 Minimal Dependencies - Single, lightweight external dependency (NetEvolve.Arguments)
  • 🔒 Null-Safe - Proper argument validation with meaningful exceptions

Installation

Install the package via NuGet Package Manager:

dotnet add package NetEvolve.Extensions.Strings

Or via the Package Manager Console:

Install-Package NetEvolve.Extensions.Strings

Usage

EnsureEndsWith

Ensures that a string ends with the specified suffix. If the string already ends with the suffix, the original string is returned; otherwise, the suffix is appended.

using System;

string path = "C:\\Users\\Documents";
string result = path.EnsureEndsWith("\\"); 
// Result: "C:\\Users\\Documents\\"

string url = "https://example.com/";
string result2 = url.EnsureEndsWith("/");
// Result: "https://example.com/" (unchanged, already ends with "/")

// Case-insensitive comparison
string text = "Hello";
string result3 = text.EnsureEndsWith("WORLD", StringComparison.OrdinalIgnoreCase);
// Result: "HelloWORLD"

Parameters:

  • value (string): The string to check
  • suffix (string): The suffix to ensure
  • comparison (StringComparison): Optional comparison mode (default: CurrentCulture)

Exceptions:

  • ArgumentNullException: Thrown if value or suffix is null

EnsureStartsWith

Ensures that a string starts with the specified prefix. If the string already starts with the prefix, the original string is returned; otherwise, the prefix is prepended.

using System;

string path = "Documents\\file.txt";
string result = path.EnsureStartsWith("C:\\");
// Result: "C:\\Documents\\file.txt"

string url = "example.com";
string result2 = url.EnsureStartsWith("https://");
// Result: "https://example.com"

// Case-insensitive comparison
string text = "world";
string result3 = text.EnsureStartsWith("HELLO", StringComparison.OrdinalIgnoreCase);
// Result: "HELLOworld"

Parameters:

  • value (string): The string to check
  • prefix (string): The prefix to ensure
  • comparison (StringComparison): Optional comparison mode (default: CurrentCulture)

Exceptions:

  • ArgumentNullException: Thrown if value or prefix is null

Supported Frameworks

  • .NET Standard 2.0
  • .NET 8.0
  • .NET 9.0
  • .NET 10.0

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Links

About

Library with common `string` extension methods for easy reuse

Topics

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.