IvanStoychev.Useful.String.Extensions
5.0.0
Prefix Reserved
dotnet add package IvanStoychev.Useful.String.Extensions --version 5.0.0
NuGet\Install-Package IvanStoychev.Useful.String.Extensions -Version 5.0.0
<PackageReference Include="IvanStoychev.Useful.String.Extensions" Version="5.0.0" />
paket add IvanStoychev.Useful.String.Extensions --version 5.0.0
#r "nuget: IvanStoychev.Useful.String.Extensions, 5.0.0"
// Install IvanStoychev.Useful.String.Extensions as a Cake Addin #addin nuget:?package=IvanStoychev.Useful.String.Extensions&version=5.0.0 // Install IvanStoychev.Useful.String.Extensions as a Cake Tool #tool nuget:?package=IvanStoychev.Useful.String.Extensions&version=5.0.0
Source and debug symbols embedded
(You can step through this package's code during debug)
What is this?
A library of extension methods for the string
class that make work with text easier.
How do I get started?
Add using IvanStoychev.Useful.String.Extensions;
And call methods on any string.
Video Demonstration
(Will open in YouTube)
Examples:
Remove all occurrences of a collection of strings
string testString = "To buy: Eggs. eggs. Jam. Ham. Milk. ham. Bread. Bread";
List<string> stringsToRemove = new() { "Eggs. ", "Ham. ", ". Bread" };
string outputDefault = testString.Remove(stringsToRemove);
string outputIgnoreCase = testString.Remove(stringsToRemove, StringComparison.InvariantCultureIgnoreCase);
Console.WriteLine(outputDefault);
Console.WriteLine(outputIgnoreCase);
// Result
// ------
// outputDefault = "To buy: eggs. Jam. Milk. ham"
// outputIgnoreCase = "To buy: Jam. Milk"
.
Replace all occurrences of a collection of strings with another string
string testString = "Gold. Gems. Jewels. Trinkets. More gems. More jewels!";
List<string> oldStrings = new() { "Gems", "Jewels", "Trinkets" };
string outputDefault = testString.Replace("gold", oldStrings);
string outputIgnoreCase = testString.Replace("gold", oldStrings, StringComparison.InvariantCultureIgnoreCase);
Console.WriteLine(outputDefault);
Console.WriteLine(outputIgnoreCase);
// Result
// ------
// outputDefault = "Gold. gold. gold. gold. More gems. More jewels!"
// outputIgnoreCase = "Gold. gold. gold. gold. More gold. More gold!"
.
Select everything between two substrings
string testString = "We start on Monday and we finish on Tuesday.";
string startString = "start on ";
string endString = " and we finish";
string outputDefault = testString.Substring(startString, endString);
string outputFull = testString.Substring(startString, endString, StringInclusionOptions.IncludeAll);
Console.WriteLine(outputDefault);
Console.WriteLine(outputFull);
// Result
// ------
// outputDefault = "Monday"
// outputFull = "start on Monday and we finish"
.
Select everything after/before a substring
string testString = "In the beginning there was bread. In the end there was jam.";
string startString = "bread. ";
string endString = " In the end";
string outputStart = testString.SubstringStart(endString);
string outputEnd = testString.SubstringEnd(startString);
Console.WriteLine(outputStart);
Console.WriteLine(outputEnd);
// Result
// ------
// outputStart = "In the beginning there was bread."
// outputEnd = "In the end there was jam."
.
All methods have a detailed summary. For a complete list of all methods in the library and details on them consult the wiki.
Feel free to submit any issues or bugs to the project's GitHub issues page. You are welcome to follow my projects twitter.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.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.
L͟e͟g͟e͟n͟d͟:
💜 - Bug fix
🟢 - New feature
🔴 - Removed feature
🟡 - Altered existing feature
______________________________________
💜 Fixed some test names, test data and added missing tests for "TrimStart" and "TrimEnd" methods.
🟢 Updated library to .Net 8.
🟡 Changed library class structure to additionally facilitate users. Now all classes are partial and named "StringExtensions" to allow users to have their own classes using the old class names. File names remain unchanged for ease of structural navigation.