ktsu.Sorting 1.0.2-pre.2

Prefix Reserved
This is a prerelease version of ktsu.Sorting.
dotnet add package ktsu.Sorting --version 1.0.2-pre.2
                    
NuGet\Install-Package ktsu.Sorting -Version 1.0.2-pre.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ktsu.Sorting" Version="1.0.2-pre.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ktsu.Sorting" Version="1.0.2-pre.2" />
                    
Directory.Packages.props
<PackageReference Include="ktsu.Sorting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ktsu.Sorting --version 1.0.2-pre.2
                    
#r "nuget: ktsu.Sorting, 1.0.2-pre.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=ktsu.Sorting&version=1.0.2-pre.2&prerelease
                    
Install ktsu.Sorting as a Cake Addin
#tool nuget:?package=ktsu.Sorting&version=1.0.2-pre.2&prerelease
                    
Install ktsu.Sorting as a Cake Tool

ktsu.Sorting

A .NET library that provides advanced sorting utilities for specialized sorting scenarios.

Overview

ktsu.Sorting offers a collection of sorting utilities to address common sorting challenges that aren't easily handled by standard sorting methods. The library is designed to be modular and extensible, allowing you to use only the components you need.

Components

NaturalStringComparer

The first component in the ktsu.Sorting library is the NaturalStringComparer, which provides natural string comparison by treating embedded numeric parts as numbers rather than characters.

Problem

Standard string sorting sorts strings character by character, which results in unintuitive ordering for strings containing numbers:

"file1.txt"
"file10.txt"
"file2.txt"
Solution

NaturalStringComparer sorts strings the way a human would expect, recognizing and comparing embedded numbers as numeric values:

"file1.txt"
"file2.txt"
"file10.txt"

Installation

Package Manager

Install-Package ktsu.Sorting

.NET CLI

dotnet add package ktsu.Sorting

Usage

Using NaturalStringComparer

using ktsu.Sorting;

// Create a comparer instance
var comparer = new NaturalStringComparer();

// Compare individual strings
int result = comparer.Compare("file10.txt", "file2.txt"); // Returns > 0 (10 > 2)

// Sort an array using the natural comparer
string[] files = { "file10.txt", "file1.txt", "file100.txt", "file2.txt" };
Array.Sort(files, comparer);
// Result: "file1.txt", "file2.txt", "file10.txt", "file100.txt"

// Use with LINQ
var sortedFiles = files.OrderBy(file => file, new NaturalStringComparer());

Features

NaturalStringComparer

  • Correctly sorts strings containing numbers in a human-friendly order
  • Handles mixed alphanumeric strings
  • Properly compares strings with leading zeros
  • Fully compatible with .NET's IComparer<string> interface
  • Can be used with Array.Sort(), LINQ's OrderBy(), and other sorting mechanisms

Examples

NaturalStringComparer Examples

The NaturalStringComparer correctly sorts strings like:

Input Standard Sort Natural Sort
file1.txt file1.txt file1.txt
file10.txt file10.txt file2.txt
file2.txt file2.txt file10.txt
------------------------------- -------------------------------
z1.doc z1.doc z1.doc
z10.doc z10.doc z2.doc
z17.doc z17.doc z3.doc
z2.doc z2.doc z10.doc
z23.doc z23.doc z17.doc
z3.doc z3.doc z23.doc

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Product 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.  net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.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.

Version Downloads Last updated
1.0.2-pre.2 113 5/20/2025
1.0.2-pre.1 110 5/18/2025
1.0.1 431 5/17/2025
1.0.0 87 5/17/2025

## v1.0.2-pre.2

Initial release or repository with no prior history.