Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

885 Commits

Repository files navigation

NetEvolve.Extensions.Strings

NuGetNuGet DownloadsLicense

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.

usingSystem;stringpath="C:\\Users\\Documents";stringresult=path.EnsureEndsWith("\\");// Result: "C:\\Users\\Documents\\"stringurl="https://example.com/";stringresult2=url.EnsureEndsWith("/");// Result: "https://example.com/" (unchanged, already ends with "/")// Case-insensitive comparisonstringtext="Hello";stringresult3=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.

usingSystem;stringpath="Documents\\file.txt";stringresult=path.EnsureStartsWith("C:\\");// Result: "C:\\Documents\\file.txt"stringurl="example.com";stringresult2=url.EnsureStartsWith("https://");// Result: "https://example.com"// Case-insensitive comparisonstringtext="world";stringresult3=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

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages