budul.StringExtensions 2.0.0

dotnet add package budul.StringExtensions --version 2.0.0
                    
NuGet\Install-Package budul.StringExtensions -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="budul.StringExtensions" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="budul.StringExtensions" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="budul.StringExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add budul.StringExtensions --version 2.0.0
                    
#r "nuget: budul.StringExtensions, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package budul.StringExtensions@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=budul.StringExtensions&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=budul.StringExtensions&version=2.0.0
                    
Install as a Cake Tool

StringExtensions

Multiple extension methods to adjust or manipulate strings.

NuGet

The package targets .NET 10 only and has nullable reference types enabled.

Installation

dotnet add package budul.StringExtensions
using StringExtensions;

Methods

Method Description
Add(value, delimiter = ",") Appends the trimmed value, separated by the delimiter. Empty values are ignored.
AddOnce(value, delimiter = ",") Like Add, but only if the value is not yet an entry of the delimited string.
GetCommon() Longest substring shared by all non-empty strings of a sequence. Candidates start at the beginning of a word.
IsAllDigits() true if the string consists of ASCII digits only.
IsConsecutiveDigits() true if the string contains digits and they are not interrupted by other characters.
IsEmpty() true for null, empty and whitespace strings.
IsEqualOrEmpty(other) true if one of both is empty or both are equal.
Join(delimiter = ",") / Extensions.Join(delimiter, params values) Joins the trimmed, non-empty values.
RemoveAccents() Removes diacritics by Unicode normalization, e.g. ü becomes u.
Repeat(count) Repeats the string count times.
Shrink(maxLength = 0, toCamelCases = false) Shortens a string by removing whitespaces and inner vowels, fitting it into maxLength (0 means unlimited).
Split<T>(delimiters, excludeEmpties = false, provider = null) Splits by a regular expression and converts the entries to T.
Split<T>(delimiter, excludeEmpties = false, provider = null) Same for a single plain character (not interpreted as regular expression).
Split(length) Splits into chunks of the given length.
SplitLines(excludeEmpties = false) Splits at \r\n, \r and \n.
ToCamelCases() First character upper case, all others lower case.
ToStandardChars() Replaces special letters by their basic Latin counterpart, e.g. Ð becomes D.
Truncate(maxLength, extension) Cuts the string to maxLength including the extension, e.g. ....
Truncate(maxLength, shrinkIfNecessary = false) Cuts the string to maxLength, optionally shrinking it first.

Examples

"a".Add("b");                                   // "a,b"
"a,b".AddOnce("b");                             // "a,b"
"abc,d".AddOnce("ab");                          // "abc,d,ab"

new[] { "AB1", "AB2" }.GetCommon();             // "AB"

"1a".IsConsecutiveDigits();                     // true
"1ab1".IsConsecutiveDigits();                   // false

"Zürich".RemoveAccents();                       // "Zurich"
"Ðorf".ToStandardChars();                       // "Dorf"
"ABCDEF".ToCamelCases();                        // "Abcdef"

"Banovce nad Bebravou".Shrink(8);               // "BnvcnBbr"
"Banovce nad Bebravou".Shrink(8, true);         // "BnvcNBbr"

"1,2;3".Split<int>("[,;]");                     // 1, 2, 3
"4|5".Split<string>('|');                       // "4", "5"
"1,5;2,5".Split<double>(";", provider: CultureInfo.GetCultureInfo("de-DE"));  // 1.5, 2.5
"0000".Split(2);                                // "00", "00"

"Ulm Hbf".Truncate(5, "...");                   // "Ul..."
"Ulm Hbf".Truncate(5);                          // "Ulm H"
"Ulm Hbf".Truncate(5, shrinkIfNecessary: true); // shortened without whitespaces

Notes

  • Split<T> converts with the invariant culture unless a format provider is given. Besides all IConvertible types, enums and Guid are supported. The result is evaluated eagerly.
  • The string delimiter overload of Split<T> expects a regular expression, the char overload does not.

Migration to 2.0

  • Only net10.0 is supported, netstandard2.0, netstandard2.1 and netcoreapp3.1 were dropped.
  • Split<T> parses with the invariant culture instead of the current culture. A char delimiter is no longer interpreted as regular expression.
  • SplitLines keeps empty lines unless excludeEmpties is set.
  • AddOnce compares whole entries instead of substrings and never returns null.
  • IsAllDigits accepts ASCII digits only. IsConsecutiveDigits also detects gaps of more than one character.
  • Shrink() without a maximum length no longer returns an empty string. A negative maximum length throws.
  • Truncate(maxLength, extension) leaves strings untouched that fit into maxLength.
  • ToStandardChars maps Ð/ð to D/d (formerly E/e).

License

MIT, see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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.

Version Downloads Last Updated
2.0.0 97 11/29/2026
1.18.2 581 7/8/2023
1.18.1 498 2/20/2023
1.18.0 516 1/29/2023
1.17.0 749 3/11/2022
1.16.0 643 5/19/2021
1.15.0 623 3/15/2021
1.14.0 653 3/10/2021
1.13.0 658 2/24/2021
1.12.0 663 1/18/2021
1.11.0 727 10/28/2020
1.9.0 713 9/14/2020
1.8.0 691 6/10/2020
1.7.0 714 6/10/2020
1.6.0 734 6/10/2020
1.5.0 721 6/4/2020
1.4.0 747 6/4/2020
1.3.0 768 6/4/2020
1.2.0 731 6/3/2020
1.1.0 735 5/5/2020
Loading failed