Skip to content

IvanStoychev/IvanStoychev.Useful.String.Extensions

Repository files navigation


IvanStoychev.Useful.String.Extensions

GitHub commit activity GitHub last commit GitHub commits since latest release (by date)
Nuget latest version GitHub latest release Project license

A collection of methods designed to make your life easier.

This repo uses Semantic Versioning 2.0.0



πŸ’¬ Join the community

Follow @ivan_stoychev
GitQ
Join the chat at https://gitter.im/IvanStoychev-Useful-String-Extensions/community
Share your thoughts in https://github.com/IvanStoychev/IvanStoychev.Useful.String.Extensions/discussions


πŸ’– Support the project

Support me on Patreon
Buy me a ko-fi
Sponsor me with PayPal
Buy me a coffee


πŸ“£ Introduction

This is a collection of string extension methods that I have been in need of many a time, so I bundled them in a nuget package and published the code here. They are designed to be "ease-of-life" and "generally making your life easier" methods with user comfort in mind, which is why there are numerious overloads, designed for every case I could think of.


🎬 Demo

(Will open in YouTube)

Demonstration video


πŸš€ Features

  • Substring methods that use string arguments to determine a substring's position, instead of a starting index.
    • Ex. "This is the start bla bladdy blah.".Substring("start ", false) will return "bla bladdy blah.", while "This is the start bla bladdy blah and this is the end.".Substring("start ", "blah", StringInclusionOptions.IncludeNone) will return "bla bladdy ".
  • Replace methods that take a series of strings or characters and replace all their occurrences in the original string with a provided value.
    • Ex. "Cucumbers, oranges and apples are vegetables.".Replace("tomatoes", "oranges", "apples") will return "Cucumbers, tomatoes and tomatoes are vegetables.".
  • Contains methods that check if a string contains any of a series of provided values.
    • Ex. "brake wheel icon number stoic".Contains("keen", "wild", "icon") will return true.
  • Remove methods that take a series of strings or characters and clear all their occurrences from the string with a single method call.
    • Ex. "Lorem ipsum dolor Lorem ipsum sit amet".Remove("Lorem ", "ipsum ", "t") will return "dolor si ame".
  • TrimStart and TrimEnd methods that take a string and remove it from the start or end of the original string.
    • Ex. "In the beginning there was an end".TrimStart("In the beginning ") will return "there was an end", while "In the beginning there was an end".TrimEnd(" an end") will produce "In the beginning there was".
  • Methods to keep or remove all special characters, letters and digits from a string.
    • Ex. "!#%&lorem^@ipsum!@%".KeepOnlyLetters() will return "loremipsum".
  • And much more.

πŸ— Installation

Install using "NuGet Package Manager" in Visual Studio
1. Open the solution to which you wish to add the library.
2. Open the "NuGet Package Manager".

  • Option 1 (allows installation to multiple projects in the solution)
    In "Solution Explorer" right-click the solution and choose "Manage NuGet Packages for Solution...".
  • Option 2 (allows installation to multiple projects in the solution)
    Click the "Tools" menu bar item, navigate to "NuGet Package Manager" and select "Manage NuGet Packages for Solution...".
  • Option 3 (allows installation only to a single project)
    Right-click the project, to which you wish to add the library, and choose "Manage NuGet Packages...".


3. Make sure your "Package source:" (found in the upper-right corner) is pointing to a nuget source that has the library in its catalogue, for example "nuget.org".
4. Make sure you're in the "Browse" section (located in the upper-left corner).
5. Enter "IvanStoychev.Useful.String.Extensions" in the search box.
6. Select the "IvanStoychev.Useful.String.Extensions" package and choose a version to intall.
6.1. If you've opened the Package Manager using option 1 or 2 you can select which projects to install the library to.
7. Click the "Install" button and read the licence terms. Choose whether you agree to them or not.


Install manually
1.a. Download the package from NuGet, Github packages or the Releases page.
-or-
1.b. Clone the repo and build in it "Release" mode, which will produce a package file in the project's release dir - "~\IvanStoychev.Useful.String.Extensions\IvanStoychev.Useful.String.Extensions\bin\Release".
2. Make sure you have the .NET CLI installed.
3. Open a command line and Run the command dotnet add <PROJECT> package <PACKAGE>.
where:
<PROJECT> is the path to the *.csproj file to which you want to add the package (if it is located in the command line's working directory you can omit this parameter).
<PACKAGE> is the path to the package you have downloaded.

Install using "Package Manager Console"
1. Run this command in the "Package Manager Console": Install-Package IvanStoychev.Useful.String.Extensions.

Install using PackageReference
1. Add this line, in an "<ItemGroup>", to your .csproj file <PackageReference Include="IvanStoychev.Useful.String.Extensions" Version="VersionNumber"/>.
where:
VersionNumber is the version of the package you wish to use, e.g. 1.0.0.

Install using Paket CLI
1. Run the command paket add IvanStoychev.Useful.String.Extensions.


β„Ή How to use

Since the functionality, added by this project, is all extension methods, it would be best to add the using statment "using IvanStoychev.Useful.String.Extensions;" to your code, as Intellisense usually doesn't pick it up.


🎞 Examples

The following examples use top-level statements.


Select an amount of characters from a string, using a substring as a reference

using IvanStoychev.Useful.String.Extensions;

string original = "Alice-A Bob-B Clayton-C";
string result = original.Substring("Bob", 2);
Console.WriteLine(result);

// output:
//
// -B

Select everything up to/after a substring

using IvanStoychev.Useful.String.Extensions;

string original = "Press any button";
string beginning = original.SubstringStart(" any ");
string ending = original.SubstringEnd(" any ");
Console.WriteLine(beginning);
Console.WriteLine(ending);

// output:
//
// Press
// button

Select everything between two substrings

using IvanStoychev.Useful.String.Extensions;

string original = "Press any button";
string result = original.Substring("Press ", " button");
Console.WriteLine(result);

// output:
//
// any

πŸ“– Documentation

The methods in the package and project have ample summary information, you can also consult the Wiki.


πŸ§™β€ Contribution

Feel free to make issues and pull requests about anything.

About

A .Net library of useful extension methods for the "string" class in C#.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages