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
value
stringThe string to search.
searchFor
stringThe 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
value
string
Returns
- bool
EmptyAsNull(string?)
Maps empty strings to null.
[Pure]
public static string? EmptyAsNull(this string? value)
Parameters
value
string
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
value
stringsearchFor
stringrest
string
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
value
stringsearchFor
string
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
s1
strings2
string
Returns
- bool
EqualsIgnoreCase(char, char)
Compares chars using case-insensitive comparison.
[Pure]
public static bool EqualsIgnoreCase(char c1, char c2)
Parameters
c1
charc2
char
Returns
- bool
EqualsIgnoreCase(string?, string?)
Compares strings using case-insensitive comparison.
[Pure]
public static bool EqualsIgnoreCase(string? s1, string? s2)
Parameters
s1
strings2
string
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
value
longThe value in bytes.
provider
IFormatProviderProvides 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
length
intThe 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
value
stringsearchFor
char
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
value
stringsearchFor
string
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
value
stringsearchFor
char
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
value
stringsearchFor
string
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
value
stringsearchFor
char
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
value
stringsearchFor
string
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
value
stringsearchFor
char
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
value
stringsearchFor
string
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
separator
stringThe separator characters to place between the
parts
.parts
IEnumerable<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
value
stringcharacters
IEnumerable<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
value
string
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
value
stringsearchFor
stringrest
string
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
value
stringsearchFor
string
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
value
stringmaxLength
int
Returns
- string