{"id":15409207,"url":"https://github.com/augustoproiete/naturalstringextensions","last_synced_at":"2025-04-14T00:42:03.389Z","repository":{"id":38455834,"uuid":"328788549","full_name":"augustoproiete/NaturalStringExtensions","owner":"augustoproiete","description":"Extensions for sorting strings using natural sort order i.e. Alphabetical order for humans","archived":false,"fork":false,"pushed_at":"2025-03-22T11:12:55.000Z","size":217,"stargazers_count":33,"open_issues_count":8,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T14:52:37.425Z","etag":null,"topics":["c-sharp","csharp","dotnet","hacktoberfest","natural-sort","natural-sorting","nuget","sort","string","string-compare","string-comparison","string-extensions"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/augustoproiete.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"augustoproiete"}},"created_at":"2021-01-11T20:52:11.000Z","updated_at":"2025-03-20T00:26:11.000Z","dependencies_parsed_at":"2024-01-27T03:24:16.464Z","dependency_job_id":"97f7aa7a-32da-4023-a48f-fcaa86257e0e","html_url":"https://github.com/augustoproiete/NaturalStringExtensions","commit_stats":{"total_commits":170,"total_committers":4,"mean_commits":42.5,"dds":"0.41764705882352937","last_synced_commit":"229cccf2ea67754b5f7eb52b5fec5f0de5c2395d"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustoproiete%2FNaturalStringExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustoproiete%2FNaturalStringExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustoproiete%2FNaturalStringExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustoproiete%2FNaturalStringExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/augustoproiete","download_url":"https://codeload.github.com/augustoproiete/NaturalStringExtensions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804719,"owners_count":21164127,"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","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","csharp","dotnet","hacktoberfest","natural-sort","natural-sorting","nuget","sort","string","string-compare","string-comparison","string-extensions"],"created_at":"2024-10-01T16:38:26.758Z","updated_at":"2025-04-14T00:42:03.357Z","avatar_url":"https://github.com/augustoproiete.png","language":"C#","readme":"| README.md |\n|:---|\n\n\u003cdiv align=\"center\"\u003e\n\n![NaturalStringExtensions](asset/natural-string-extensions-logo.png)\n\n\u003c/div\u003e\n\n\u003ch1 align=\"center\"\u003eNaturalStringExtensions\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n\n Micro-library for sorting strings using natural sort order i.e. Alphabetical order for humans.\n\n[![NuGet Version](http://img.shields.io/nuget/v/NaturalStringExtensions.svg?style=flat-square)](https://www.nuget.org/packages/NaturalStringExtensions/) [![.NET 5+](https://img.shields.io/badge/.NET%20-%3E%3D%205.0-512bd4)](https://dotnet.microsoft.com/download) [![.NET Standard 2.0](https://img.shields.io/badge/.NET%20Standard-%3D%202.0-512bd4)](https://dotnet.microsoft.com/download) [![.NET Framework 4.6.1+](https://img.shields.io/badge/.NET%20Framework%20-%3E%3D%204.6.1-512bd4)](https://dotnet.microsoft.com/download) [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-c%23-05930c.svg?style=flat-square)](http://stackoverflow.com/questions/tagged/c%23)\n\n\u003c/div\u003e\n\n## Give a Star! :star:\n\nIf you like or are using this project please give it a star. Thanks!\n\n## Background\n\nA common scenario in many applications is ordering of string data using natural sort order.\n\nNatural sort order is an ordering of strings in alphabetical order, except that multi-digit numbers are treated atomically, i.e., as if they were a single character. Natural sort order has been promoted as being more human-friendly (\"natural\") than the machine-oriented pure alphabetical order.\n\nFor example, in alphabetical sorting `Folder11` would be sorted before `Folder2` because `1` is sorted as smaller than `2`, while in natural sorting `Folder2` is sorted before `Folder11` because `2` is sorted as smaller than `11`.\n\n\u003cdiv align=\"center\"\u003e\n\n| Alphabetical   | Natural                       |     | Alphabetical  | Natural                      |\n| -------------- | ----------------------------- | --- | ------------- | ---------------------------- |\n| `Folder1`      | `Folder1`                     |     | `v1.2.0`      | `v1.2.0`                     |\n| `Folder10` :x: | `Folder2`                     |     | `v10.1.0` :x: | `v2.0.0`                     |\n| `Folder11` :x: | `Folder10` :white_check_mark: |     | `v10.5.3` :x: | `v2.1.0`                     |\n| `Folder2`      | `Folder11` :white_check_mark: |     | `v2.0.0`      | `v3.1.0`                     |\n| `Folder20`     | `Folder20`                    |     | `v2.1.0`      | `v10.1.0` :white_check_mark: |\n| `Folder35`     | `Folder35`                    |     | `v3.1.0`      | `v10.5.3` :white_check_mark: |\n\n\u003c/div\u003e\n\nExample scenarios where `NaturalStringExtensions` can be useful include sorting of file names, folder names, and version numbers.\n\n## Getting started :rocket:\n\nInstall the [NaturalStringExtensions](https://www.nuget.org/packages/NaturalStringExtensions) package from NuGet:\n\n```powershell\nInstall-Package NaturalStringExtensions\n```\n\nUse one of the `IEnumerable\u003cT\u003e` extension methods to sort a list based on a string field, using natural sort order:\n\n```csharp\nvar folderNames = new[]\n{\n    \"Folder20\",\n    \"Folder1\",\n    \"Folder2\",\n    \"Folder10\",\n};\n\nvar sortedfolderNames = folderNames.OrderByNatural();\n\nforeach (var folderName in sortedfolderNames)\n{\n    Console.WriteLine(folderName);\n}\n\n```\n\nOutput:\n\n```\nFolder1\nFolder2\nFolder10\nFolder20\n```\n\n---\n\nIn the [sample](sample/) folder, there's an example of a Console application that uses `NaturalStringExtensions` to order a list of versions using natural sort order, as described above.\n\n## Extension methods\n\nUse one of the `IEnumerable\u003cT\u003e` extension methods to sort a list based on a string field, using a natural sort order:\n\n| Extension method           | Description                                                                              |\n| -------------------------- | ---------------------------------------------------------------------------------------- |\n| `OrderByNatural`           | Sorts the elements of a sequence in natural ascending order                              |\n| `OrderByNaturalDescending` | Sorts the elements of a sequence in natural descending order                             |\n| `ThenByNatural`            | Performs a subsequent ordering of the elements in a sequence in natural ascending order  |\n| `ThenByNaturalDescending`  | Performs a subsequent ordering of the elements in a sequence in natural descending order |\n\n## NaturalStringComparer\n\nA `NaturalStringComparer` class that implements `IComparer\u003cstring\u003e` is available for comparing strings using a natural sort order:\n\n```csharp\nconst string left = \"Folder 10\";\nconst string right = \"Folder 5\";\n\nvar result = new NaturalStringComparer().Compare(left, right);\n// 1 -\u003e \"Folder 10\" is \u003e \"Folder 5\"\n```\n\nFor convenience, the `NaturalStringComparer` class has a static property called `Instance` with a thread-safe instance of `NaturalStringComparer` ready for use, which is also cached upon first use.\n\n```csharp\nusing System.IO;\n// ...\n\nvar currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());\n\nvar sortedDirectoryNames = currentDirectory.EnumerateDirectories()\n    .OrderBy(d =\u003e d.FullName, NaturalStringComparer.Ordinal);\n```\n\n### Sorting Arrays without LINQ\n\n```csharp\nvar folderNames = new[]\n{\n    \"Folder1000\",\n    \"Folder200\",\n    \"Folder30\",\n    \"Folder4\",\n};\n\nArray.Sort(folderNames, NaturalStringComparer.Ordinal);\n\n// Contents of folderNames array:\n//\n// Folder4\n// Folder30\n// Folder200\n// Folder1000\n//\n```\n\n## Release History\n\nClick on the [Releases](https://github.com/augustoproiete/NaturalStringExtensions/releases) tab on GitHub.\n\n---\n\n_Copyright \u0026copy; 2021-2023 C. Augusto Proiete \u0026 Contributors - Provided under the [Apache License, Version 2.0](LICENSE). `NaturalStringExtensions` logo is a derivative of work by [Benjamin STAWARZ](https://www.iconfinder.com/bensta) ([original](https://www.iconfinder.com/icons/6138342/desc_direction_down_numeric_sort_filter_icon))._\n","funding_links":["https://github.com/sponsors/augustoproiete"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faugustoproiete%2Fnaturalstringextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faugustoproiete%2Fnaturalstringextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faugustoproiete%2Fnaturalstringextensions/lists"}