CoreSuite.Extensions
1.0.0
See the version list below for details.
dotnet add package CoreSuite.Extensions --version 1.0.0
NuGet\Install-Package CoreSuite.Extensions -Version 1.0.0
<PackageReference Include="CoreSuite.Extensions" Version="1.0.0" />
<PackageVersion Include="CoreSuite.Extensions" Version="1.0.0" />
<PackageReference Include="CoreSuite.Extensions" />
paket add CoreSuite.Extensions --version 1.0.0
#r "nuget: CoreSuite.Extensions, 1.0.0"
#:package CoreSuite.Extensions@1.0.0
#addin nuget:?package=CoreSuite.Extensions&version=1.0.0
#tool nuget:?package=CoreSuite.Extensions&version=1.0.0
CoreSuite.Extensions
General-purpose string and collection utilities for .NET 8 applications.
CoreSuite.Extensions is one of the libraries included in the CoreSuite solution. It targets plain .NET 8 and has no CoreSuite or third-party package dependencies.
Overview
CoreSuite.Extensions provides small, reusable operations for manipulating strings and retrieving a single object from a collection. The package includes character and word reversal, word counting, diacritic removal, title and camel-case conversion, first-occurrence replacement, extra-space removal and object creation when a collection contains no matching element.
Because the package does not depend on Windows Forms, it can be used in desktop applications, services, console applications, class libraries and other .NET 8 projects.
Features
- Reverses all characters in a string.
- Reverses the order of space-separated words.
- Counts words separated by spaces, tabs or line breaks.
- Removes accents and other Unicode non-spacing marks.
- Converts text to title case using the current culture.
- Converts space-, underscore- or hyphen-separated text to camel case.
- Replaces only the first occurrence of a substring.
- Collapses repeated spaces between text fragments.
- Retrieves a single collection element or creates a new instance when no element is found.
- Includes English XML documentation for the public API.
- Requires no third-party packages.
Requirements
- .NET 8 (
net8.0)
Installation
Install the package from NuGet:
dotnet add package CoreSuite.Extensions
Or use the Visual Studio NuGet Package Manager and search for:
CoreSuite.Extensions
Namespace
Import the namespace containing the extension modules:
Imports CoreSuite.Extensions.Extensions
Quick start
Imports CoreSuite.Extensions.Extensions
Dim ReversedText As String = "CoreSuite".ReverseText()
Dim ReversedWords As String = "CoreSuite Extensions".ReverseWords()
Dim WordCount As Integer = "Reusable .NET utilities".CountWords()
Dim UnaccentedText As String = "Configuração".ToUnaccented()
Dim CamelName As String = "customer-order_number".ToCamel()
Dim CompactText As String = "CoreSuite Extensions".RemoveExtraSpaces()
API reference
String extensions
| Member | Behavior |
|---|---|
ReverseText() |
Returns the characters in reverse order. |
ReverseWords() |
Returns space-separated words in reverse order. |
CountWords() |
Counts fragments separated by spaces, tabs, carriage returns or line feeds. |
ToUnaccented() |
Decomposes Unicode text and removes non-spacing marks. |
ToTitle() |
Converts text to title case using the current thread culture. |
ToCamel() |
Converts words separated by spaces, underscores or hyphens to camel case. |
ReplaceFirst(oldValue, newValue) |
Replaces only the first occurrence of oldValue. |
RemoveExtraSpaces() |
Removes empty fragments created by repeated space characters. |
Collection utility
| Member | Behavior |
|---|---|
FirstOrNew(source, predicate) |
Returns the single matching element or attempts to create a new instance of the collection element type when no match exists. |
String examples
Reverse characters or words
Dim Characters As String = "Hello World".ReverseText()
Dim Words As String = "Hello World".ReverseWords()
The results are dlroW olleH and World Hello, respectively.
Normalize text for comparison
Dim SearchText As String = "João da Silva".ToUnaccented().ToLowerInvariant()
ToUnaccented removes Unicode non-spacing marks. It does not perform case conversion, so a separate casing operation can be applied when required.
Convert naming styles
Dim Title As String = "CUSTOMER ORDER".ToTitle()
Dim PropertyName As String = "customer-order_number".ToCamel()
ToTitle and the casing operations used by ToCamel are culture-sensitive.
Replace only the first occurrence
Dim Result As String = "one two one".ReplaceFirst("one", "first")
The result is first two one.
Remove repeated spaces
Dim Result As String = "CoreSuite Extensions".RemoveExtraSpaces()
The result is CoreSuite Extensions. This method treats the space character as its separator; tabs and line breaks are not collapsed.
Retrieve one element or create a new instance
FirstOrNew uses single-element semantics. It is useful when a query should return zero or one item and the calling code prefers a newly created object when no match exists.
Imports CoreSuite.Extensions.Extensions
Dim Customer As Customer = CollectionExtensions.FirstOrNew(Customers, Function(Item) Item.Id = CustomerId)
Important behavior:
- More than one matching element causes
InvalidOperationException. - When no element is found, the method attempts to create the item type through
Activator.CreateInstance. Nothingis returned when the type cannot be created with a parameterless constructor.- The source collection must not be
Nothing.
Empty-value behavior
| Member | Nothing or empty input |
|---|---|
ReverseText |
Returns String.Empty. |
ReverseWords |
Returns String.Empty. |
CountWords |
Returns 0. |
ToUnaccented |
Returns String.Empty. |
ToTitle |
Returns Nothing. |
ToCamel |
Requires a non-Nothing string. |
ReplaceFirst |
Requires valid input and search values. |
RemoveExtraSpaces |
Requires a non-Nothing string. |
Package information
| Item | Value |
|---|---|
| Package | CoreSuite.Extensions |
| Namespace | CoreSuite.Extensions.Extensions |
| Assembly | CoreSuite.Extensions |
| Target framework | net8.0 |
| CoreSuite dependencies | None |
| External dependencies | None |
License
This package is distributed under the MIT License defined by the CoreSuite repository.
| Product | Versions 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 was computed. 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. |
-
net8.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.
Initial release of the collection and string utilities.