|
7 | 7 | [](LICENSE) |
8 | 8 |
|
9 | 9 | [](https://codecov.io/gh/TJC-Tools/TJC.StringExtensions) |
10 | | - |
11 | | -## Table of Contents |
12 | | -- [Pluralize](#pluralize) |
13 | | -- [Separator](#separator) |
14 | | -- [Parsing](#parsing) |
15 | | -- [Lines](#lines) |
16 | | -- [Padding](#padding) |
17 | | - |
18 | | ---- |
19 | | - |
20 | | -## Pluralize |
21 | | - |
22 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[Pluralize](./TJC.StringExtensions/Pluralize/PluralizeExtensions.cs)(int number, string? pluralized = null) |
23 | | -- Takes a string and pluralizes it based on the number provided. |
24 | | -```c# |
25 | | -var item = "apple"; |
26 | | -var plural = item.Pluralize(2); |
27 | | -Console.WriteLine(plural); // apples |
28 | | -``` |
29 | | - |
30 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [IEnumerable](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable?view=net-8.0)\<object\>.[Pluralize](./TJC.StringExtensions/Pluralize/PluralizeExtensions.cs)(string nonPluralized, string? pluralized = null) |
31 | | -- Takes a collection of objects and pluralizes a string based on the number of objects in the collection. |
32 | | -```c# |
33 | | -// Multiple items in a collection results in a pluralized string |
34 | | -var itemsMultiple = new List<string> { "item1", "item2", "item3" }; |
35 | | -var plural = itemsMultiple.Pluralize("item"); |
36 | | -Console.WriteLine(plural); // items |
37 | | -
|
38 | | -// A single item in a collection results in a singular string |
39 | | -var itemsSingle = new List<string> { "item1" }; |
40 | | -var singluar = itemsSingle.Pluralize("item"); |
41 | | -Console.WriteLine(singluar); // item |
42 | | -``` |
43 | | - |
44 | | ---- |
45 | | - |
46 | | -## Separator |
47 | | - |
48 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [IEnumerable](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable?view=net-8.0)\<[string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0)\>.[JoinComma](./TJC.StringExtensions/Separator/SeparatorExtensions.cs)() |
49 | | -- Joins a collection of strings with a comma and space. |
50 | | -```c# |
51 | | -var items = new List<string> { "one", "two", "three" }; |
52 | | -var result = items.JoinComma(); // one, two, three |
53 | | -``` |
54 | | - |
55 | | ---- |
56 | | - |
57 | | -## Parsing |
58 | | - |
59 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[KeepAlpha](./TJC.StringExtensions/Parsing/StringParserExtensions.cs)() |
60 | | -- Keep letters only. |
61 | | -```c# |
62 | | -// Arrange |
63 | | -var input = "a1!b2@c3#.d4$ e5%"; |
64 | | -var result = input.KeepAlpha(); // abcde |
65 | | -``` |
66 | | - |
67 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[KeepNumeric](./TJC.StringExtensions/Parsing/StringParserExtensions.cs)() |
68 | | -- Keep numbers only. |
69 | | -```c# |
70 | | -// Arrange |
71 | | -var input = "a1!b2@c3#.d4$ e5%"; |
72 | | -var result = input.KeepNumeric(); // 12345 |
73 | | -``` |
74 | | - |
75 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[KeepNumericAndPeriod](./TJC.StringExtensions/Parsing/StringParserExtensions.cs)() |
76 | | -- Keep numbers and periods only. |
77 | | -```c# |
78 | | -// Arrange |
79 | | -var input = "a1!b2@c3#.d4$ e5%"; |
80 | | -var result = input.KeepNumericAndPeriod(); // 123.45 |
81 | | -``` |
82 | | - |
83 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[KeepAlphaNumeric](./TJC.StringExtensions/Parsing/StringParserExtensions.cs)() |
84 | | -- Keep letters and numbers only. |
85 | | -```c# |
86 | | -// Arrange |
87 | | -var input = "a1!b2@c3#.d4$ e5%"; |
88 | | -var result = input.KeepAlphaNumeric(); // a1b2c3d4e5 |
89 | | -``` |
90 | | - |
91 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[KeepAlphaNumericAndSpace](./TJC.StringExtensions/Parsing/StringParserExtensions.cs)() |
92 | | -- Keep letters, numbers, and spaces only. |
93 | | -```c# |
94 | | -// Arrange |
95 | | -var input = "a1!b2@c3#.d4$ e5%"; |
96 | | -var result = input.KeepAlphaNumericAndSpace(); // a1b2c3d4 e5 |
97 | | -``` |
98 | | - |
99 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[RemoveSymbols](./TJC.StringExtensions/Parsing/StringParserExtensions.cs)(char[]? exceptions = null) |
100 | | -- Remove symbols from a string, except any exceptions provided. |
101 | | -```c# |
102 | | -// Arrange |
103 | | -var input = "a1!b2@c3#.d4$ e5%"; |
104 | | -var result = input.RemoveSymbols(['!', '.']); // a1!b2c3.d4 e5 |
105 | | -``` |
106 | | - |
107 | | ---- |
108 | | - |
109 | | -## Lines |
110 | | - |
111 | | -### [IEnumerable](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable?view=net-8.0)\<[string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0)\> [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[SplitNewLine](./TJC.StringExtensions/Lines/LineExtensions.cs)() |
112 | | -- Splits a string into lines on a new line character. |
113 | | - |
114 | | -### [IEnumerable](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable?view=net-8.0)\<[string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0)\> [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[SplitLines](./TJC.StringExtensions/Lines/LineExtensions.cs)(int width = 60, char separator = ' ') |
115 | | -- Splits a string into lines of a max width with a separator character. |
116 | | - |
117 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[RemoveMultipleBlankLines](./TJC.StringExtensions/Lines/LineExtensions.cs)() |
118 | | -- Remove multiple blank lines from a string. |
119 | | - |
120 | | ---- |
121 | | - |
122 | | -## Padding |
123 | | - |
124 | | -### [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0) [string](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0).[PadBoth](./TJC.StringExtensions/Padding/PaddingExtensions.cs)([int](https://learn.microsoft.com/en-us/dotnet/api/system.int32?view=net-8.0) length) |
125 | | -- Pads both side of a string so that it's centered between the padding |
0 commit comments