A collection of useful string extension methods
$ dotnet add package Soenneker.Extensions.String
Soenneker.Extensions.StringA highly optimized library of string extension methods designed to improve performance, readability, and efficiency in .NET applications. This library is ideal for developers looking to streamline common string operations while adhering to best practices and achieving maximum performance.
dotnet add package Soenneker.Extensions.String
string longString = "This is a long string that needs to be truncated";
string truncatedString = longString.Truncate(10);
// truncatedString = "This is a ..."string alphanumeric = "abc123";
bool isAlphanumeric = alphanumeric.IsAlphaNumeric();
// isAlphanumeric = true
string nonAlphanumeric = "abc123!";
bool isNonAlphanumeric = nonAlphanumeric.IsAlphaNumeric();
// isNonAlphanumeric = falsestring test = "this string&is%bad#for\\urls"
test.Slugify() // "this-string-is-bad-for-urls"string numericString = "3.14";
double? doubleValue = numericString.ToDouble();
// doubleValue = 3.14
string nonNumericString = "abc";
double? nonDoubleValue = nonNumericString.ToDouble();
// nonDoubleValue = nullstring stringWithNonDigits = "abc123xyz456";
string digitsOnly = stringWithNonDigits.RemoveNonDigits();
// digitsOnly = "123456"string originalString = "hello";
string shuffledString = originalString.Shuffle();
// shuffledString = "olhel"... and more