Class StringUtils
Provides additional or simplified string functions.
Assembly: NanoByte.Common.dll
Syntax
public static class StringUtils : Object
Methods
ContainsIgnoreCase(String, String)
Determines whether a string contains searchFor
using case-insensitive comparison.
Declaration
public static bool ContainsIgnoreCase(this string value, string searchFor)
Parameters
Type |
Name |
Description |
String |
value |
The string to search.
|
String |
searchFor |
The string to search for in value .
|
Returns
ContainsWhitespace(String)
Determines whether a string contains any whitespace characters.
Declaration
public static bool ContainsWhitespace(this string value)
Parameters
Type |
Name |
Description |
String |
value |
|
Returns
EndsWith(String, String, out String)
Determines whether a string starts with searchFor
and, if so, returns the rest
that comes before.
Declaration
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.
Declaration
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.
Declaration
public static bool EqualsEmptyNull(string s1, string s2)
Parameters
Returns
EqualsIgnoreCase(Char, Char)
Compares chars using case-insensitive comparison.
Declaration
public static bool EqualsIgnoreCase(char c1, char c2)
Parameters
Type |
Name |
Description |
System.Char |
c1 |
|
System.Char |
c2 |
|
Returns
EqualsIgnoreCase(String, String)
Compares strings using case-insensitive comparison.
Declaration
public static bool EqualsIgnoreCase(string s1, string s2)
Parameters
Returns
Formats a byte number in human-readable form (KB, MB, GB).
Declaration
public static string FormatBytes(this long value, IFormatProvider provider = null)
Parameters
Type |
Name |
Description |
Int64 |
value |
The value in bytes.
|
IFormatProvider |
provider |
Provides culture-specific formatting information.
|
Returns
GeneratePassword(Int32)
Returns a string filled with random human-readable ASCII characters based on a cryptographic random number generator.
Declaration
public static string GeneratePassword(int length)
Parameters
Type |
Name |
Description |
Int32 |
length |
The length of the string to be generated.
|
Returns
GetLeftPartAtFirstOccurrence(String, Char)
Get everything to the left of the first occurrence of a character.
Declaration
public static string GetLeftPartAtFirstOccurrence(this string value, char searchFor)
Parameters
Type |
Name |
Description |
String |
value |
|
System.Char |
searchFor |
|
Returns
GetLeftPartAtFirstOccurrence(String, String)
Get everything to the left of the first occurrence of a string.
Declaration
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.
Declaration
public static string GetLeftPartAtLastOccurrence(this string value, char searchFor)
Parameters
Type |
Name |
Description |
String |
value |
|
System.Char |
searchFor |
|
Returns
GetLeftPartAtLastOccurrence(String, String)
Get everything to the left of the last occurrence of a string.
Declaration
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.
Declaration
public static string GetRightPartAtFirstOccurrence(this string value, char searchFor)
Parameters
Type |
Name |
Description |
String |
value |
|
System.Char |
searchFor |
|
Returns
GetRightPartAtFirstOccurrence(String, String)
Get everything to the right of the first occurrence of a string.
Declaration
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.
Declaration
public static string GetRightPartAtLastOccurrence(this string value, char searchFor)
Parameters
Type |
Name |
Description |
String |
value |
|
System.Char |
searchFor |
|
Returns
GetRightPartAtLastOccurrence(String, String)
Get everything to the right of the last occurrence of a string.
Declaration
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
.
Declaration
public static string Join(string separator, IEnumerable<string> parts)
Parameters
Type |
Name |
Description |
String |
separator |
The separator characters to place between the parts .
|
IEnumerable<String> |
parts |
The strings to be combined.
|
Returns
RemoveCharacters(String, IEnumerable<Char>)
Removes all occurrences of a specific set of characters from a string.
Declaration
public static string RemoveCharacters(this string value, IEnumerable<char> characters)
Parameters
Returns
SplitMultilineText(String)
Splits a multiline string to several strings and returns the result as a string array.
Declaration
public static string[] SplitMultilineText(this string value)
Parameters
Type |
Name |
Description |
String |
value |
|
Returns
StartsWith(String, String, out String)
Determines whether a string starts with searchFor
and, if so, returns the rest
that comes after.
Declaration
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.
Declaration
public static bool StartsWithIgnoreCase(this string value, string searchFor)
Parameters
Returns
TrimOverflow(String, Int32)
Cuts off strings longer than maxLength
and replaces the rest with ellipsis (...).
Declaration
public static string TrimOverflow(this string value, int maxLength)
Parameters
Returns