{"id":17008724,"url":"https://github.com/i-e-b/string_extensions","last_synced_at":"2025-06-13T06:32:12.258Z","repository":{"id":17097180,"uuid":"19862544","full_name":"i-e-b/String_Extensions","owner":"i-e-b","description":"A big pile of string manipulation methods for C#","archived":false,"fork":false,"pushed_at":"2025-03-03T09:59:18.000Z","size":666,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T20:02:01.463Z","etag":null,"topics":["c-sharp","string-manipulation","string-matching","working"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/i-e-b.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}},"created_at":"2014-05-16T16:05:16.000Z","updated_at":"2025-03-03T09:59:21.000Z","dependencies_parsed_at":"2024-11-11T15:33:20.390Z","dependency_job_id":"5f67f108-bffa-415a-adf2-5fc6a591b51b","html_url":"https://github.com/i-e-b/String_Extensions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/i-e-b/String_Extensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-e-b%2FString_Extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-e-b%2FString_Extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-e-b%2FString_Extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-e-b%2FString_Extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i-e-b","download_url":"https://codeload.github.com/i-e-b/String_Extensions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-e-b%2FString_Extensions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259594357,"owners_count":22881641,"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","string-manipulation","string-matching","working"],"created_at":"2024-10-14T05:29:08.384Z","updated_at":"2025-06-13T06:32:12.225Z","avatar_url":"https://github.com/i-e-b.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"String_Extensions\r\n=================\r\n\r\nA big pile of string manipulation methods for C#, to fill in some of the gaps of the default string library.\r\n\r\nhttps://www.nuget.org/packages/StringExtensionsNetStdIeb/\r\n\r\n## Comparison\r\n\r\n### CompareWildcard\r\n\r\nMatch strings to patterns using `*` and `?` placeholders. For when Regex is too much.\r\n\r\n### NaturalComparer\r\n\r\nA comparer for use in Linq `Sort(...)` that respects numerical ordering.\r\n\r\nYou can drop this anywhere an IComparer is used on strings. To sort files by name with numbers in the right place:\r\n```csharp\r\nvar list = new DirectoryInfo(@\"C:\\temp\")\r\n    .GetFiles()\r\n    .OrderBy(f=\u003ef.Name, new NaturalComparer())\r\n    .ToList();\r\n```\r\n.OrderBy(f=\u003ef.Name, new NaturalComparer()).ToList()\r\n\r\nThen, given these files (as ordered by default .Net sort)\r\n\r\n\u003e File 10, File 11, File 8, File 9\r\n\r\nWill be sorted correctly, as would be expected:\r\n\r\n\u003e File 8, File 9, File 10, File 11\r\n\r\n### NumbersOnlyComparer\r\n\r\nSimilar to `NaturalComparer`, but sorts only on number parts of strings. Strings without numbers are sorted last.\r\n\r\nAll number values are treated as positive integers, with the `-`, `.`, `,` characters interpreted as separators.\r\n\r\nGiven \r\n\r\n`File`, `Users 2020-01-01`, `Accounts 2020-02-03`, `Accounts 2020-02-03_v2`\r\n\r\nthis will output\r\n\r\n`Users 2020-01-01`, `Accounts 2020-02-03`, `Accounts 2020-02-03_v2`, `File`\r\n\r\n### EqualsIgnoreNumbers\r\n\r\nCompare strings for equality, ignoring the actual values of decimal numbers\r\n\r\n`NaturalComparer.EqualsIgnoreNumbers(\"Added ID 5 to DB\", \"Added ID 201 to DB\")` == `true`\r\n\r\n`NaturalComparer.EqualsIgnoreNumbers(\"Added ID 5 to DB\", \"ID 201 Failed\")` == `false`\r\n\r\n## Parsing and ToString\r\n\r\n### ToByteArray\r\n\r\nConvert hex strings to byte arrays.\r\n\r\nTake a string like `BADF00BA` into a byte array. String length should be a multiple of two.\r\n\r\n### Approximate\r\n\r\nConvert a `TimeSpan` to a string approximation based on scale, from seconds to years\r\n\r\n### TimeLag\r\n\r\nSame as `Approximate`, but from two `DateTime` values.\r\n\r\n## Replacement\r\n\r\n### ReplaceCaseInvariant\r\n\r\nReplace string fragments using a case-insensitive search.\r\n\r\nMatching is case invariant, replacement is done preserving case.\r\nFor example: `\"OnCe UpOn A tImE\".ReplaceCaseInvariant(\"TiMe\", \"Moon\") == \"OnCe UpOn A Moon\"`\r\n\r\n### ReplaceAsciiCompatible\r\n\r\nReplace latin-like letters and numbers with their ASCII equivalents.\r\n\r\nThis will replace accented forms with ones that *look* similar, but it\r\nwill often destroy or change meaning. Do **NOT** use this to present output\r\nto users. It is intended to use for stored search targets.\r\nThis is not exhaustive, and does not handle characters that are not latin-like (e.g. CJK)\r\n\r\n`HÉLLO, Åbjørn!\".ReplaceAsciiCompatible() == \"HELLO, Abjorn!\"`\r\n\r\n### CamelCaseToWords\r\n\r\nConvert `camelCase` or `PascalCase` fused-word strings into space separated words.\r\n\r\n`MyABCsDoCamelCasePhrase\".CamelCaseToWords() == \"My ABCs Do Camel Case Phrase\"`\r\n\r\n### Switch case simple\r\n\r\nFast case switching on strings that only makes changes that don't change the number\r\nof characters in the string.\r\n\r\n`\"123 £%$: AAA aaa ǉ ǆ ß\".ToUpperSimple() == \"123 £%$: AAA AAA Ǉ Ǆ ß\"`\r\n\r\n`\"123 £%$: AAA aaa Ǉ Ǆ SS\".ToLowerSimple() == \"123 £%$: aaa aaa ǉ ǆ ss\"`\r\n\r\n### Switch case of single character\r\n\r\nSet casing of characters in the string\r\n\r\n`\"hello, world\".UpperCaseIndex(0) == \"Hello, world\"`\r\n\r\n`\"hello, world\".UpperCaseIndex(-5) == \"hello, World\"`\r\n\r\n## Searching\r\n\r\n### FindCluster\r\n\r\nA very simple O(n+m) algorithm for finding clusters of characters in a string.\r\n(i.e. it will find `wxyz` in `abc zwyx abc`, but not in `ab xy ab wz`)\r\n\r\nThis algorithm will give some false positives where the sum of character values match.\r\n\r\n## Substrings\r\n\r\nA range of substring before/after first/last instances of a character or string.\r\n\r\n### SubstringBefore\r\n\r\nReturn the substring up to but not including the first instance of string 's'.\r\nIf 's' is not found, the entire string is returned.\r\n\r\n`\"once upon a time\".SubstringBefore(\"upon\") == \"once \"`\r\n\r\n### SubstringBeforeLast\r\n\r\nReturn the substring up to but not including the last instance of string 's'.\r\nIf 's' is not found, the entire string is returned.\r\n\r\n`\"once upon a time up high\".SubstringBeforeLast(\"up\") == \"once upon a time \"`\r\n\r\n### SubstringAfter\r\n\r\nReturn the substring after to but not including the first instance of string 's'.\r\nIf 's' is not found, the entire string is returned.\r\n\r\n`\"it happened once upon a time\".SubstringAfter(\"once\") == \" upon a time\"`\r\n\r\n### SubstringAfterLast\r\n\r\nReturn the substring after to but not including the last instance of string 's'.\r\nIf 's' is not found, the entire string is returned.\r\n\r\n`\"once upon a time\".SubstringAfterLast(\"on\") == \" a time\"`\r\n\r\n### IndexAfter / LastIndexAfter\r\n\r\nReturn the index of the first character after a match.\r\nIf match is not found, `-1` is returned.\r\n\r\n`\"once upon a time\".IndexAfter(\"on\") == 2`\r\n`\"once upon a time\".LastIndexAfter(\"on\") == 9`\r\n\r\n## Filtering\r\n\r\n### NormaliseWhitespace\r\n\r\nReplace all runs of whitespace with a single space character\r\n\r\n```csharp\r\nvar output = \"This\\tis\\u00a0a  story about \\r\\n a \\rperson\\n\\t\\r\\n named Not, who was    tall.\"\r\n        .NormaliseWhitespace(char.IsLower);\r\n```\r\n\r\nresults in `This is a story about a person named Not, who was tall.`\r\n\r\n### FilterCharacters\r\n\r\nRemove a string omitting characters where the function returns `true`\r\n\r\n```csharp\r\nvar output = \"Hello, World! How are you?\"\r\n        .FilterCharacters(char.IsLower);\r\n```\r\n\r\nresults in `H, W! H  ?`\r\n\r\n\r\n### Remove\r\n\r\nReturn a string with all instances of all given unwanted strings removed,\r\nmatched case sensitive.\r\n\r\n```csharp\r\nvar output = \"This is not a short story about a person named Not, who was not short but tall.\"\r\n        .Remove(new[]{\"not\", \"short\", \"but\"})\r\n```\r\n\r\nresults in `This is  a  story about a person named Not, who was    tall.`\r\n\r\n### RemoveCaseInvariant\r\n\r\nReturn a string with all instances of all given unwanted strings removed,\r\nmatched case insensitive.\r\n\r\n```csharp\r\nvar output = \"This is not a short story about a person named Not, who was not short but tall.\"\r\n        .RemoveCaseInvariant(new[]{\"not\", \"short\", \"but\"})\r\n```\r\n\r\nresults in `This is  a  story about a person named , who was    tall.`\r\n\r\n\r\n### RemoveNumbers\r\n\r\nRemove a string omitting all decimal digit characters.\r\n\r\n```csharp\r\nvar output = \"In 2024 at 12.15pm, we found 7 stone lions in a cave 250 miles from 9th Avenue\"\r\n        .RemoveNumbers()\r\n```\r\n\r\nresults in `In  at .pm, we found  stone lions in a cave  miles from th Avenue`\r\n\r\n### RemoveNonAlphaNumeric\r\n\r\nKeep only ASCII alphabetic and decimal characters in the string\r\n\r\n```csharp\r\nvar output = \"In 2024, we found 7 stone lions in a cave 250 miles from 9th Avenue.\"\r\n        .RemoveNonAlphaNumeric()\r\n```\r\n\r\nresults in `In2024wefound7stonelionsinacave250milesfrom9thAvenue`\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi-e-b%2Fstring_extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi-e-b%2Fstring_extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi-e-b%2Fstring_extensions/lists"}