Class StringUtils
Provides additional or simplified string functions.
public static class StringUtils
  - Inheritance
 - 
      objectStringUtils
 
Methods
ContainsIgnoreCase(string, string)
Determines whether a string contains searchFor using case-insensitive comparison.
[Pure]
public static bool ContainsIgnoreCase(this string value, string searchFor)
  Parameters
valuestringThe string to search.
searchForstringThe string to search for in
value.
Returns
- bool
 
ContainsWhitespace(string)
Determines whether a string contains any whitespace characters.
[Pure]
public static bool ContainsWhitespace(this string value)
  Parameters
valuestring
Returns
- bool
 
EmptyAsNull(string?)
Maps empty strings to null.
[Pure]
public static string? EmptyAsNull(this string? value)
  Parameters
valuestring
Returns
- string
 
EndsWith(string, string, out string)
Determines whether a string starts with searchFor and, if so, returns the rest that comes before.
[Pure]
public static bool EndsWith(this string value, string searchFor, out string rest)
  Parameters
valuestringsearchForstringreststring
Returns
- bool
 
EndsWithIgnoreCase(string, string)
Determines whether a string ends with searchFor with case-insensitive comparison.
[Pure]
public static bool EndsWithIgnoreCase(this string value, string searchFor)
  Parameters
valuestringsearchForstring
Returns
- bool
 
EqualsEmptyNull(string?, string?)
Compares strings using case-sensitive, invariant culture comparison and considering null and string.Empty equal.
[Pure]
public static bool EqualsEmptyNull(string? s1, string? s2)
  Parameters
s1strings2string
Returns
- bool
 
EqualsIgnoreCase(char, char)
Compares chars using case-insensitive comparison.
[Pure]
public static bool EqualsIgnoreCase(char c1, char c2)
  Parameters
c1charc2char
Returns
- bool
 
EqualsIgnoreCase(string?, string?)
Compares strings using case-insensitive comparison.
[Pure]
public static bool EqualsIgnoreCase(string? s1, string? s2)
  Parameters
s1strings2string
Returns
- bool
 
FormatBytes(long, IFormatProvider?)
Formats a byte number in human-readable form (KB, MB, GB).
public static string FormatBytes(this long value, IFormatProvider? provider = null)
  Parameters
valuelongThe value in bytes.
providerIFormatProviderProvides culture-specific formatting information.
Returns
- string
 
GeneratePassword(int)
Returns a string filled with random human-readable ASCII characters based on a cryptographic random number generator.
[Pure]
public static string GeneratePassword(int length)
  Parameters
lengthintThe length of the string to be generated.
Returns
- string
 
GetLeftPartAtFirstOccurrence(string, char)
Get everything to the left of the first occurrence of a character.
[Pure]
public static string GetLeftPartAtFirstOccurrence(this string value, char searchFor)
  Parameters
valuestringsearchForchar
Returns
- string
 
GetLeftPartAtFirstOccurrence(string, string)
Get everything to the left of the first occurrence of a string.
[Pure]
public static string GetLeftPartAtFirstOccurrence(this string value, string searchFor)
  Parameters
valuestringsearchForstring
Returns
- string
 
GetLeftPartAtLastOccurrence(string, char)
Get everything to the left of the last occurrence of a character.
[Pure]
public static string GetLeftPartAtLastOccurrence(this string value, char searchFor)
  Parameters
valuestringsearchForchar
Returns
- string
 
GetLeftPartAtLastOccurrence(string, string)
Get everything to the left of the last occurrence of a string.
[Pure]
public static string GetLeftPartAtLastOccurrence(this string value, string searchFor)
  Parameters
valuestringsearchForstring
Returns
- string
 
GetRightPartAtFirstOccurrence(string, char)
Get everything to the right of the first occurrence of a character.
[Pure]
public static string GetRightPartAtFirstOccurrence(this string value, char searchFor)
  Parameters
valuestringsearchForchar
Returns
- string
 
GetRightPartAtFirstOccurrence(string, string)
Get everything to the right of the first occurrence of a string.
[Pure]
public static string GetRightPartAtFirstOccurrence(this string value, string searchFor)
  Parameters
valuestringsearchForstring
Returns
- string
 
GetRightPartAtLastOccurrence(string, char)
Get everything to the right of the last occurrence of a character.
[Pure]
public static string GetRightPartAtLastOccurrence(this string value, char searchFor)
  Parameters
valuestringsearchForchar
Returns
- string
 
GetRightPartAtLastOccurrence(string, string)
Get everything to the right of the last occurrence of a string.
[Pure]
public static string GetRightPartAtLastOccurrence(this string value, string searchFor)
  Parameters
valuestringsearchForstring
Returns
- string
 
Join(string, IEnumerable<string>)
Combines multiple strings into one, placing a separator between the parts.
[Pure]
public static string Join(string separator, IEnumerable<string> parts)
  Parameters
separatorstringThe separator characters to place between the
parts.partsIEnumerable<string>The strings to be combined.
Returns
- string
 
RemoveCharacters(string?, IEnumerable<char>)
Removes all occurrences of a specific set of characters from a string.
[Pure]
public static string? RemoveCharacters(this string? value, IEnumerable<char> characters)
  Parameters
valuestringcharactersIEnumerable<char>
Returns
- string
 
SplitMultilineText(string)
Splits a multiline string to several strings and returns the result as a string array.
[Pure]
public static IEnumerable<string> SplitMultilineText(this string value)
  Parameters
valuestring
Returns
- IEnumerable<string>
 
StartsWith(string, string, out string)
Determines whether a string starts with searchFor and, if so, returns the rest that comes after.
[Pure]
public static bool StartsWith(this string value, string searchFor, out string rest)
  Parameters
valuestringsearchForstringreststring
Returns
- bool
 
StartsWithIgnoreCase(string, string)
Determines whether a string starts with searchFor with case-insensitive comparison.
[Pure]
public static bool StartsWithIgnoreCase(this string value, string searchFor)
  Parameters
valuestringsearchForstring
Returns
- bool
 
TrimOverflow(string, int)
Cuts off strings longer than maxLength and replaces the rest with ellipsis (...).
public static string TrimOverflow(this string value, int maxLength)
  Parameters
valuestringmaxLengthint
Returns
- string