{"id":32945941,"url":"https://github.com/tompazourek/NaturalSort.Extension","last_synced_at":"2025-11-12T20:00:41.208Z","repository":{"id":26851054,"uuid":"111156169","full_name":"tompazourek/NaturalSort.Extension","owner":"tompazourek","description":"🔀 Extension method for StringComparison that adds support for natural sorting (e.g. \"abc1\", \"abc2\", \"abc10\" instead of \"abc1\", \"abc10\", \"abc2\").","archived":false,"fork":false,"pushed_at":"2025-10-28T15:04:51.000Z","size":331,"stargazers_count":200,"open_issues_count":5,"forks_count":18,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-11-11T03:31:38.553Z","etag":null,"topics":["c-sharp","comparer","extension-methods","natural-sort","naturalsort","sort","sorting","string","string-comparison","stringcomparer","stringcomparison"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tompazourek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-11-17T22:19:05.000Z","updated_at":"2025-11-01T22:22:35.000Z","dependencies_parsed_at":"2023-10-15T10:18:29.052Z","dependency_job_id":"6566336b-680c-4dc0-8e1f-c4c61672ff7f","html_url":"https://github.com/tompazourek/NaturalSort.Extension","commit_stats":{"total_commits":82,"total_committers":2,"mean_commits":41.0,"dds":"0.23170731707317072","last_synced_commit":"1c28de269c00b5feebefa2bc7b842752b5e63188"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/tompazourek/NaturalSort.Extension","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompazourek%2FNaturalSort.Extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompazourek%2FNaturalSort.Extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompazourek%2FNaturalSort.Extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompazourek%2FNaturalSort.Extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tompazourek","download_url":"https://codeload.github.com/tompazourek/NaturalSort.Extension/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompazourek%2FNaturalSort.Extension/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284017249,"owners_count":26933277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-12T02:00:06.336Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","comparer","extension-methods","natural-sort","naturalsort","sort","sorting","string","string-comparison","stringcomparer","stringcomparison"],"created_at":"2025-11-12T18:00:25.874Z","updated_at":"2025-11-12T20:00:41.203Z","avatar_url":"https://github.com/tompazourek.png","language":"C#","funding_links":[],"categories":["高性能数据结构和算法","Misc","杂项","Audio","C# #"],"sub_categories":["FPS","GUI - other"],"readme":"# ![NaturalSort.Extension logo](https://raw.githubusercontent.com/tompazourek/NaturalSort.Extension/master/assets/logo_32.png) NaturalSort.Extension\r\n\r\n*Extension method for `StringComparison` or any `IComparer\u003cstring\u003e` that adds support for natural sorting  (e.g. \"abc1\", \"abc2\", \"abc10\" instead of \"abc1\", \"abc10\", \"abc2\").*\r\n\r\n[![Build status](https://img.shields.io/appveyor/ci/tompazourek/naturalsort-extension/master.svg)](https://ci.appveyor.com/project/tompazourek/naturalsort-extension)\r\n[![Tests](https://img.shields.io/appveyor/tests/tompazourek/naturalsort-extension/master.svg)](https://ci.appveyor.com/project/tompazourek/naturalsort-extension/build/tests)\r\n[![codecov](https://codecov.io/gh/tompazourek/NaturalSort.Extension/branch/master/graph/badge.svg?token=31JTU6543K)](https://codecov.io/gh/tompazourek/NaturalSort.Extension)\r\n[![NuGet version](https://img.shields.io/nuget/v/NaturalSort.Extension.svg)](https://www.nuget.org/packages/NaturalSort.Extension/)\r\n[![NuGet downloads](https://img.shields.io/nuget/dt/NaturalSort.Extension.svg)](https://www.nuget.org/packages/NaturalSort.Extension/)\r\n\r\n\r\nThe library is written in C# and released with an [MIT license](https://raw.githubusercontent.com/tompazourek/NaturalSort.Extension/master/LICENSE), so feel **free to fork** or **use commercially**.\r\n\r\n**Any feedback is appreciated, please visit the [issues](https://github.com/tompazourek/NaturalSort.Extension/issues?state=open) page or send me an [e-mail](mailto:tom.pazourek@gmail.com).**\r\n\r\nDownload\r\n--------\r\n\r\nBinaries of the last build can be downloaded on the [AppVeyor CI page of the project](https://ci.appveyor.com/project/tompazourek/naturalsort-extension/build/artifacts).\r\n\r\nThe library is also [published on NuGet.org](https://www.nuget.org/packages/NaturalSort.Extension/), install using:\r\n\r\n```\r\nPM\u003e Install-Package NaturalSort.Extension\r\n```\r\n\r\n\u003csup\u003eNaturalSort.Extension is built for .NET Standard 1.3, .NET 6, and .NET 8 and is signed to allow use in projects that use strong names.\u003c/sup\u003e\r\n\r\nUsage\r\n-----\r\n\r\nThe recommended method for best results is to create the comparer by using the `StringComparison` enum.\r\n\r\n```csharp\r\nvar sequence = new[] { \"img12.png\", \"img10.png\", \"img2.png\", \"img1.png\" };\r\nvar ordered = sequence.OrderBy(x =\u003e x, StringComparison.OrdinalIgnoreCase.WithNaturalSort());\r\n// ordered will be \"img1.png\", \"img2.png\", \"img10.png\", \"img12.png\"\r\n```\r\n\r\nFor more information about natural sort order, see:\r\n\r\n- [Natural sort order (Wikipedia)](https://en.wikipedia.org/wiki/Natural_sort_order)\r\n- [Sorting for Humans: Natural Sort Order (Coding Horror)](https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/)\r\n\r\nThe `NaturalSortComparer` created using the extension method is a `IComparer\u003cstring\u003e`, which you can use in all the places that accept `IComparer\u003cstring\u003e` (e.g. `OrderBy`, `Array.Sort`, ...)\r\n\r\nIf you wish, you can be more explicit by not using the `.WithNaturalSort()` extension method, and using the constructor directly:\r\n\r\n```csharp\r\nnew NaturalSortComparer(StringComparison.OrdinalIgnoreCase)\r\n```\r\n\r\nNote that if you are using a custom `IComparer\u003cstring\u003e` (or `StringComparer`), you can also use that instead of the `StringComparison` enum. **However, if you use `StringComparison`, it should perform better as it avoids constructing substrings.**\r\n\r\nUsage as collation in SQLite\r\n----------------------------\r\n\r\nIf you're using [Microsoft.Data.Sqlite](https://docs.microsoft.com/en-us/dotnet/standard/data/sqlite/), it's also possible to use the extension as collation for use in your SQLite queries.\r\n\r\nYou can register the collation on a SQLite connection as follows (more info in [docs](https://docs.microsoft.com/en-us/dotnet/standard/data/sqlite/collation)):\r\n\r\n```csharp\r\nprivate static readonly NaturalSortComparer NaturalComparer = new(StringComparison.InvariantCultureIgnoreCase);\r\n\r\n/* ... */\r\n\r\nSqliteConnection conn;\r\nconn.CreateCollation(\"NATURALSORT\", (x, y) =\u003e NaturalComparer.Compare(x, y));\r\n```\r\n\r\nThen you can use the collation to achieve natural sorting in your SQL query:\r\n\r\n```sql\r\nSELECT * FROM Customers\r\nORDER BY Name COLLATE NATURALSORT;\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftompazourek%2FNaturalSort.Extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftompazourek%2FNaturalSort.Extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftompazourek%2FNaturalSort.Extension/lists"}