|
1 | 1 | # NetEvolve.Extensions.Strings |
2 | | -This library provides a set of extension methods for `System.String`. It is a part of the [Daily DevOps & .NET - NetEvolve](https://daily-devops.net/) project, which aims to provide a set of useful libraries for .NET developers. |
3 | 2 |
|
4 | | -## Methods |
| 3 | +[](https://www.nuget.org/packages/NetEvolve.Extensions.Strings/) |
| 4 | +[](https://www.nuget.org/packages/NetEvolve.Extensions.Strings/) |
| 5 | +[](LICENSE) |
5 | 6 |
|
6 | | -### `stringVariable.EnsureEndsWith(string, comparison)` |
7 | | -Simple helper method to determine if the `value` ends with the `suffix`. If not, it will be appended. |
| 7 | +A modern .NET library providing essential extension methods for `System.String` to simplify common string operations. Part of the [Daily DevOps & .NET - NetEvolve](https://daily-devops.net/) project. |
8 | 8 |
|
9 | | -### `stringVariable.EnsureStartsWith(string, comparison)` |
10 | | -Simple helper method to determine if the `value` ends with the `prefix`. If not, this is prefixed. |
| 9 | +## Features |
| 10 | + |
| 11 | +- 🎯 **Simple & Intuitive API** - Extension methods that feel natural to use |
| 12 | +- 🚀 **Multi-Framework Support** - Compatible with .NET Standard 2.0, .NET 8.0, .NET 9.0, and .NET 10.0 |
| 13 | +- 📦 **Minimal Dependencies** - Single, lightweight external dependency (`NetEvolve.Arguments`) |
| 14 | +- 🔒 **Null-Safe** - Proper argument validation with meaningful exceptions |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +Install the package via NuGet Package Manager: |
| 19 | + |
| 20 | +```bash |
| 21 | +dotnet add package NetEvolve.Extensions.Strings |
| 22 | +``` |
| 23 | + |
| 24 | +Or via the Package Manager Console: |
| 25 | + |
| 26 | +```powershell |
| 27 | +Install-Package NetEvolve.Extensions.Strings |
| 28 | +``` |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +### EnsureEndsWith |
| 33 | + |
| 34 | +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. |
| 35 | + |
| 36 | +```csharp |
| 37 | +using System; |
| 38 | + |
| 39 | +string path = "C:\\Users\\Documents"; |
| 40 | +string result = path.EnsureEndsWith("\\"); |
| 41 | +// Result: "C:\\Users\\Documents\\" |
| 42 | +
|
| 43 | +string url = "https://example.com/"; |
| 44 | +string result2 = url.EnsureEndsWith("/"); |
| 45 | +// Result: "https://example.com/" (unchanged, already ends with "/") |
| 46 | +
|
| 47 | +// Case-insensitive comparison |
| 48 | +string text = "Hello"; |
| 49 | +string result3 = text.EnsureEndsWith("WORLD", StringComparison.OrdinalIgnoreCase); |
| 50 | +// Result: "HelloWORLD" |
| 51 | +``` |
| 52 | + |
| 53 | +**Parameters:** |
| 54 | +- `value` (string): The string to check |
| 55 | +- `suffix` (string): The suffix to ensure |
| 56 | +- `comparison` (StringComparison): Optional comparison mode (default: `CurrentCulture`) |
| 57 | + |
| 58 | +**Exceptions:** |
| 59 | +- `ArgumentNullException`: Thrown if `value` or `suffix` is null |
| 60 | + |
| 61 | +### EnsureStartsWith |
| 62 | + |
| 63 | +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. |
| 64 | + |
| 65 | +```csharp |
| 66 | +using System; |
| 67 | + |
| 68 | +string path = "Documents\\file.txt"; |
| 69 | +string result = path.EnsureStartsWith("C:\\"); |
| 70 | +// Result: "C:\\Documents\\file.txt" |
| 71 | +
|
| 72 | +string url = "example.com"; |
| 73 | +string result2 = url.EnsureStartsWith("https://"); |
| 74 | +// Result: "https://example.com" |
| 75 | +
|
| 76 | +// Case-insensitive comparison |
| 77 | +string text = "world"; |
| 78 | +string result3 = text.EnsureStartsWith("HELLO", StringComparison.OrdinalIgnoreCase); |
| 79 | +// Result: "HELLOworld" |
| 80 | +``` |
| 81 | + |
| 82 | +**Parameters:** |
| 83 | +- `value` (string): The string to check |
| 84 | +- `prefix` (string): The prefix to ensure |
| 85 | +- `comparison` (StringComparison): Optional comparison mode (default: `CurrentCulture`) |
| 86 | + |
| 87 | +**Exceptions:** |
| 88 | +- `ArgumentNullException`: Thrown if `value` or `prefix` is null |
| 89 | + |
| 90 | +## Supported Frameworks |
| 91 | + |
| 92 | +- .NET Standard 2.0 |
| 93 | +- .NET 8.0 |
| 94 | +- .NET 9.0 |
| 95 | +- .NET 10.0 |
| 96 | + |
| 97 | +## Contributing |
| 98 | + |
| 99 | +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. |
| 100 | + |
| 101 | +## License |
| 102 | + |
| 103 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 104 | + |
| 105 | +## Links |
| 106 | + |
| 107 | +- [GitHub Repository](https://github.com/dailydevops/extensions.strings) |
| 108 | +- [NuGet Package](https://www.nuget.org/packages/NetEvolve.Extensions.Strings/) |
| 109 | +- [Release Notes](https://github.com/dailydevops/extensions.strings/releases) |
| 110 | +- [Daily DevOps & .NET](https://daily-devops.net/) |
0 commit comments