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
Returns
ContainsWhitespace(string)
Determines whether a string contains any whitespace characters.
[Pure]
public static bool ContainsWhitespace(this string value)
Parameters
valuestring
Returns
EmptyAsNull(string?)
Maps empty strings to null.
[Pure]
public static string? EmptyAsNull(this string? value)
Parameters
valuestring
Returns
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
Returns
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
Returns
EqualsEmptyNull(string?, string?)
Compares strings using case-sensitive, invariant culture comparison and considering null and Empty equal.
[Pure]
public static bool EqualsEmptyNull(string? s1, string? s2)
Parameters
Returns
EqualsIgnoreCase(char, char)
Compares chars using case-insensitive comparison.
[Pure]
public static bool EqualsIgnoreCase(char c1, char c2)
Parameters
Returns
EqualsIgnoreCase(string?, string?)
Compares strings using case-insensitive comparison.
[Pure]
public static bool EqualsIgnoreCase(string? s1, string? s2)
Parameters
Returns
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
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
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
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
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
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
Returns
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
Returns
TrimOverflow(string, int)
Cuts off strings longer than maxLength and replaces the rest with ellipsis (...).
public static string TrimOverflow(this string value, int maxLength)