NumberRanges 1.0.11
dotnet add package NumberRanges --version 1.0.11
NuGet\Install-Package NumberRanges -Version 1.0.11
<PackageReference Include="NumberRanges" Version="1.0.11" />
<PackageVersion Include="NumberRanges" Version="1.0.11" />
<PackageReference Include="NumberRanges" />
paket add NumberRanges --version 1.0.11
#r "nuget: NumberRanges, 1.0.11"
#:package NumberRanges@1.0.11
#addin nuget:?package=NumberRanges&version=1.0.11
#tool nuget:?package=NumberRanges&version=1.0.11
NumberRanges
Introduction
A simple library to manage and use integer number ranges like used on a printer: 2-10,12,15-.
Prerequisites
This package targets .NET Standard 2.1, so it should work with most .NET platforms.
Installation
Use NuGet to install the package. Use can use the UI, or use the following command in the package manager console:
Install-Package NumberRanges
Contributing
If you want to contribute, please create a pull request. I will review it as soon as possible. Use visual studio 2022 version 17.8 or later to build this library. The main library targets NETStandard 2.0, but the tests use .NET 8.0.
Author
This library was created by Jan Geert Hek, a software developer from the Netherlands. You can find more information about me on my LinkedIn page.
License
This library is licensed under the MIT License - see the LICENSE file for details.
The manual
What is a NumberRange?
A NumberRange is a range of integers. It uses the notation you may know from specifying pages when printing a document.
It can be a single number, a range of numbers, or a combination of both. The range is defined by a string, like: 2-10,12,15-
. This means any number between 2 and 10, 12, and any number that is 15 or higher.
This library can help you to check if a number is in a range, and to create a range from a string and optimizing it.
How to use NumberRanges
Using NumberRanges is easy. First, add the using statement to your code:
using NumberRanges;
Then, create a new instance of the NumberRange class. Here is a simple example.
// Any int less than 3, or between 8 and 10, or 19 or more is in the range.
var range = new NumberRange("-2,4,6-7,9-");
// Check if a number is in the range
range.Contains(1); // returns true
range.Contains(2); // returns true
range.Contains(3); // returns false
range.Contains(4); // returns true
range.Contains(5); // returns false
range.Contains(6); // returns true
range.Contains(7); // returns true
range.Contains(8); // returns false
range.Contains(9); // returns true
Here is another example, that shows creating a new instance using a fluent api to create a range:
var range = NumberRange.Empty
.AddLowerThanOrEqual(6)
.AddRange(8, 10)
.Add(15)
.Add("19-23")
.AddGreaterThanOrEqual(25);
range.ToString(); // returns "-6,8-10,15,19-23,25-"
Please note that an empty constructor and Empty
behave identical.
You can also provide an set of ranges to the constructor.
var range = NumberRange("-6", "8-10", "15,19-23", "25-");
Optimizing a range
The range 2,3,4,5,6-11,12,15-
can be optimized to 2-12,15-
. This is done by the Optimize
method.
var range = new NumberRange("2,3,4,5,6-11,12,15-");
range.ToString(); // returns "2,3,4,5,6-11,12,15-"
range.Optimize();
range.ToString(); // returns "2-12,15-"
Credits
The icon used has been designed by Flaticon.com
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- 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.