Skip to content

soenneker/soenneker.extensions.string

Repository files navigation

Soenneker.Extensions.String

A collection of useful string extension methods

Installation

dotnet add package Soenneker.Extensions.String

Usage

Truncate()

string longString = "This is a long string that needs to be truncated";
string truncatedString = longString.Truncate(10);
// truncatedString = "This is a ..."

IsAlphaNumeric()

string alphanumeric = "abc123";
bool isAlphanumeric = alphanumeric.IsAlphaNumeric();
// isAlphanumeric = true

string nonAlphanumeric = "abc123!";
bool isNonAlphanumeric = nonAlphanumeric.IsAlphaNumeric();
// isNonAlphanumeric = false

Slugify()

string test = "this string&is%bad#for\\urls"

test.Slugify() // "this-string-is-bad-for-urls"

ToDouble()

string numericString = "3.14";
double? doubleValue = numericString.ToDouble();
// doubleValue = 3.14

string nonNumericString = "abc";
double? nonDoubleValue = nonNumericString.ToDouble();
// nonDoubleValue = null

RemoveNonDigits()

string stringWithNonDigits = "abc123xyz456";
string digitsOnly = stringWithNonDigits.RemoveNonDigits();
// digitsOnly = "123456"

Shuffle()

string originalString = "hello";
string shuffledString = originalString.Shuffle();
// shuffledString = "olhel"

... and more

About

A collection of useful string extension methods

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages