Gihan.Helpers.StringHelper.NaturalStringComparer 1.5.0

Compare for string to sort by number in string (as windows explorer do)

There is a newer version of this package available.
See the version list below for details.
Install-Package Gihan.Helpers.StringHelper.NaturalStringComparer -Version 1.5.0
dotnet add package Gihan.Helpers.StringHelper.NaturalStringComparer --version 1.5.0
<PackageReference Include="Gihan.Helpers.StringHelper.NaturalStringComparer" Version="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gihan.Helpers.StringHelper.NaturalStringComparer --version 1.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

NaturalStringComparer

Build status

Pure C# code<br/>
Usable in .net core and .net framework. No need to windows api.<br/>
written int .net standard

Comparer to sort strings by numbers in them (as windows explorer do).<br/>
This is an easy to use and useful little library for programs that want to sort string naturaly by numbers.<br/>
you know 2 is lower than 11 but C# default string comparer not know this or not like this.<br/>
so you may like to use my lib for a human friendly string comparing and sorting.<br/>

var stringList = new List<string>
            {
                "number1", "number2", "number3", "number4", "number10", "number15", "number22", "number26"
                , "number9", "number33", "number5", "number12"
            };
stringList.Sort(NaturalStringComparer.Default);
Console.WriteLine("Natural Sort:");
foreach(var item in stringList)
{
  Console.WriteLine(item);
}
stringList.Sort();
Console.WriteLine();
Console.WriteLine("Normal Sort:");
foreach(var item in stringList)
{
  Console.WriteLine(item);
}
/* output
Natural Sort:
number1
number2
number3
number4
number5
number9
number10
number12
number15
number22
number26
number33

Normal Sort:
number1
number10
number12
number15
number2
number22
number26
number3
number33
number4
number5
number9
*/

NaturalStringComparer

Build status

Pure C# code<br/>
Usable in .net core and .net framework. No need to windows api.<br/>
written int .net standard

Comparer to sort strings by numbers in them (as windows explorer do).<br/>
This is an easy to use and useful little library for programs that want to sort string naturaly by numbers.<br/>
you know 2 is lower than 11 but C# default string comparer not know this or not like this.<br/>
so you may like to use my lib for a human friendly string comparing and sorting.<br/>

var stringList = new List<string>
            {
                "number1", "number2", "number3", "number4", "number10", "number15", "number22", "number26"
                , "number9", "number33", "number5", "number12"
            };
stringList.Sort(NaturalStringComparer.Default);
Console.WriteLine("Natural Sort:");
foreach(var item in stringList)
{
  Console.WriteLine(item);
}
stringList.Sort();
Console.WriteLine();
Console.WriteLine("Normal Sort:");
foreach(var item in stringList)
{
  Console.WriteLine(item);
}
/* output
Natural Sort:
number1
number2
number3
number4
number5
number9
number10
number12
number15
number22
number26
number33

Normal Sort:
number1
number10
number12
number15
number2
number22
number26
number3
number33
number4
number5
number9
*/

Release Notes

nothing changed but implementation

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.6.0 88 5/11/2019
1.5.2 103 5/3/2019
1.5.1 92 3/29/2019
1.5.0 99 3/8/2019
1.4.0 700 11/11/2018
1.3.4 178 9/19/2018
1.3.1 145 9/19/2018
1.3.0 163 8/9/2018
1.2.0 172 8/8/2018