NanoByte.Common
Static Public Member Functions | List of all members
NanoByte.Common.StringUtils Class Reference

Provides additional or simplified string functions. More...

Static Public Member Functions

static bool EqualsIgnoreCase (string? s1, string? s2)
 Compare strings using case-insensitive comparison. More...
 
static bool EqualsIgnoreCase (char c1, char c2)
 Compare chars using case-insensitive comparison. More...
 
static bool EqualsEmptyNull (string? s1, string? s2)
 Compare strings using case sensitive, invariant culture comparison and considering null and string.Empty equal. More...
 
static bool ContainsIgnoreCase (this string value, string text)
 Use case-insensitive compare to check for a contained string. More...
 
static bool ContainsWhitespace (this string value)
 Checks whether a string contains any whitespace characters More...
 
static int CountOccurrences (this string? value, char token)
 Counts how many times a character occurs within a string. More...
 
static bool StartsWithIgnoreCase (this string text, string value)
 Determines whether the beginning of this string matches a specific value case-insensitive comparison. More...
 
static bool EndsWithIgnoreCase (this string text, string value)
 Determines whether the end of this string matches a specific value case-insensitive comparison. More...
 
static ? string StripCharacters (this string? value, IEnumerable< char > characters)
 Removes all occurrences of a specific set of characters from a string. More...
 
static string StripFromEnd (this string value, int count)
 Returns a string with count characters removed from the end. More...
 
static string[] SplitMultilineText (this string value)
 Splits a multiline string to several strings and returns the result as a string array. More...
 
static string Join (string separator, IEnumerable< string > parts)
 Combines multiple strings into one, placing a separator between the parts . More...
 
static string GetLeftPartAtFirstOccurrence (this string value, char ch)
 Get everything to the left of the first occurrence of a character. More...
 
static string GetRightPartAtFirstOccurrence (this string value, char ch)
 Get everything to the right of the first occurrence of a character. More...
 
static string GetLeftPartAtLastOccurrence (this string value, char ch)
 Get everything to the left of the last occurrence of a character. More...
 
static string GetRightPartAtLastOccurrence (this string value, char ch)
 Get everything to the right of the last occurrence of a character. More...
 
static string GetLeftPartAtFirstOccurrence (this string value, string str)
 Get everything to the left of the first occurrence of a string. More...
 
static string GetRightPartAtFirstOccurrence (this string value, string str)
 Get everything to the right of the first occurrence of a string. More...
 
static string GetLeftPartAtLastOccurrence (this string value, string str)
 Get everything to the left of the last occurrence of a string. More...
 
static string GetRightPartAtLastOccurrence (this string value, string str)
 Get everything to the right of the last occurrence of a string. More...
 
static string FormatBytes (this long value, IFormatProvider? provider=null)
 Formats a byte number in human-readable form (KB, MB, GB). More...
 
static string EscapeArgument (this string value)
 Escapes a string for use as a Windows command-line argument, making sure it is encapsulated within " if it contains whitespace characters. More...
 
static string JoinEscapeArguments (this IEnumerable< string > parts)
 Combines multiple strings into one for use as a Windows command-line argument using EscapeArgument. More...
 
static string Base64Utf8Encode (this string value)
 Encodes a string as UTF-8 in base64. More...
 
static string Base64Utf8Decode (this string value)
 Decodes a UTF-8 in base64 string. More...
 
static string Base32Encode (this byte[] data)
 Encodes a byte array in base32 without padding. More...
 
static string Base16Encode (this byte[] data)
 Encodes a byte array in base16 (hexadecimal). More...
 
static byte[] Base16Decode (this string encoded)
 Decodes a base16 (hexadecimal) to a byte array. More...
 
static string Hash (this string value, HashAlgorithm algorithm)
 Computes the hash value of a string encoded as UTF-8. More...
 
static string GeneratePassword (int length)
 Returns a string filled with random human-readable ASCII characters based on a cryptographic random number generator. More...
 

Detailed Description

Provides additional or simplified string functions.

Member Function Documentation

◆ Base16Decode()

static byte [] NanoByte.Common.StringUtils.Base16Decode ( this string  encoded)
inlinestatic

Decodes a base16 (hexadecimal) to a byte array.

◆ Base16Encode()

static string NanoByte.Common.StringUtils.Base16Encode ( this byte[]  data)
inlinestatic

Encodes a byte array in base16 (hexadecimal).

◆ Base32Encode()

static string NanoByte.Common.StringUtils.Base32Encode ( this byte[]  data)
inlinestatic

Encodes a byte array in base32 without padding.

◆ Base64Utf8Decode()

static string NanoByte.Common.StringUtils.Base64Utf8Decode ( this string  value)
inlinestatic

Decodes a UTF-8 in base64 string.

Exceptions
FormatExceptionvalue is not a valid base 64 string.

◆ Base64Utf8Encode()

static string NanoByte.Common.StringUtils.Base64Utf8Encode ( this string  value)
inlinestatic

Encodes a string as UTF-8 in base64.

◆ ContainsIgnoreCase()

static bool NanoByte.Common.StringUtils.ContainsIgnoreCase ( this string  value,
string  text 
)
inlinestatic

Use case-insensitive compare to check for a contained string.

Parameters
valueThe string to search.
textThe string to search for in value .

◆ ContainsWhitespace()

static bool NanoByte.Common.StringUtils.ContainsWhitespace ( this string  value)
inlinestatic

Checks whether a string contains any whitespace characters

◆ CountOccurrences()

static int NanoByte.Common.StringUtils.CountOccurrences ( this string?  value,
char  token 
)
inlinestatic

Counts how many times a character occurs within a string.

Parameters
valueThe string to search within.
tokenThe character to search for.
Returns
The number of occurrences of token within value .

◆ EndsWithIgnoreCase()

static bool NanoByte.Common.StringUtils.EndsWithIgnoreCase ( this string  text,
string  value 
)
inlinestatic

Determines whether the end of this string matches a specific value case-insensitive comparison.

◆ EqualsEmptyNull()

static bool NanoByte.Common.StringUtils.EqualsEmptyNull ( string?  s1,
string?  s2 
)
inlinestatic

Compare strings using case sensitive, invariant culture comparison and considering null and string.Empty equal.

◆ EqualsIgnoreCase() [1/2]

static bool NanoByte.Common.StringUtils.EqualsIgnoreCase ( char  c1,
char  c2 
)
static

Compare chars using case-insensitive comparison.

◆ EqualsIgnoreCase() [2/2]

static bool NanoByte.Common.StringUtils.EqualsIgnoreCase ( string?  s1,
string?  s2 
)
static

Compare strings using case-insensitive comparison.

◆ EscapeArgument()

static string NanoByte.Common.StringUtils.EscapeArgument ( this string  value)
inlinestatic

Escapes a string for use as a Windows command-line argument, making sure it is encapsulated within " if it contains whitespace characters.

This corresponds to Windows' handling of command-line arguments as specified in: http://msdn.microsoft.com/library/17w5ykft

◆ FormatBytes()

static string NanoByte.Common.StringUtils.FormatBytes ( this long  value,
IFormatProvider?  provider = null 
)
inlinestatic

Formats a byte number in human-readable form (KB, MB, GB).

Parameters
valueThe value in bytes.
providerProvides culture-specific formatting information.

◆ GeneratePassword()

static string NanoByte.Common.StringUtils.GeneratePassword ( int  length)
inlinestatic

Returns a string filled with random human-readable ASCII characters based on a cryptographic random number generator.

Parameters
lengthThe length of the string to be generated.

◆ GetLeftPartAtFirstOccurrence() [1/2]

static string NanoByte.Common.StringUtils.GetLeftPartAtFirstOccurrence ( this string  value,
char  ch 
)
inlinestatic

Get everything to the left of the first occurrence of a character.

◆ GetLeftPartAtFirstOccurrence() [2/2]

static string NanoByte.Common.StringUtils.GetLeftPartAtFirstOccurrence ( this string  value,
string  str 
)
inlinestatic

Get everything to the left of the first occurrence of a string.

◆ GetLeftPartAtLastOccurrence() [1/2]

static string NanoByte.Common.StringUtils.GetLeftPartAtLastOccurrence ( this string  value,
char  ch 
)
inlinestatic

Get everything to the left of the last occurrence of a character.

◆ GetLeftPartAtLastOccurrence() [2/2]

static string NanoByte.Common.StringUtils.GetLeftPartAtLastOccurrence ( this string  value,
string  str 
)
inlinestatic

Get everything to the left of the last occurrence of a string.

◆ GetRightPartAtFirstOccurrence() [1/2]

static string NanoByte.Common.StringUtils.GetRightPartAtFirstOccurrence ( this string  value,
char  ch 
)
inlinestatic

Get everything to the right of the first occurrence of a character.

◆ GetRightPartAtFirstOccurrence() [2/2]

static string NanoByte.Common.StringUtils.GetRightPartAtFirstOccurrence ( this string  value,
string  str 
)
inlinestatic

Get everything to the right of the first occurrence of a string.

◆ GetRightPartAtLastOccurrence() [1/2]

static string NanoByte.Common.StringUtils.GetRightPartAtLastOccurrence ( this string  value,
char  ch 
)
inlinestatic

Get everything to the right of the last occurrence of a character.

◆ GetRightPartAtLastOccurrence() [2/2]

static string NanoByte.Common.StringUtils.GetRightPartAtLastOccurrence ( this string  value,
string  str 
)
inlinestatic

Get everything to the right of the last occurrence of a string.

◆ Hash()

static string NanoByte.Common.StringUtils.Hash ( this string  value,
HashAlgorithm  algorithm 
)
inlinestatic

Computes the hash value of a string encoded as UTF-8.

Parameters
valueThe string to hash.
algorithmThe hashing algorithm to use.
Returns
A hexadecimal string representation of the hash value.

◆ Join()

static string NanoByte.Common.StringUtils.Join ( string  separator,
IEnumerable< string >  parts 
)
inlinestatic

Combines multiple strings into one, placing a separator between the parts .

Parameters
separatorThe separator characters to place between the parts .
partsThe strings to be combined.

Works like string.Join(string,string[]) but for IEnumerable<T>s.

◆ JoinEscapeArguments()

static string NanoByte.Common.StringUtils.JoinEscapeArguments ( this IEnumerable< string >  parts)
inlinestatic

Combines multiple strings into one for use as a Windows command-line argument using EscapeArgument.

Parameters
partsThe strings to be combined.

This corresponds to Windows' handling of command-line arguments as specified in: http://msdn.microsoft.com/library/17w5ykft

◆ SplitMultilineText()

static string [] NanoByte.Common.StringUtils.SplitMultilineText ( this string  value)
inlinestatic

Splits a multiline string to several strings and returns the result as a string array.

◆ StartsWithIgnoreCase()

static bool NanoByte.Common.StringUtils.StartsWithIgnoreCase ( this string  text,
string  value 
)
inlinestatic

Determines whether the beginning of this string matches a specific value case-insensitive comparison.

◆ StripCharacters()

static ? string NanoByte.Common.StringUtils.StripCharacters ( this string?  value,
IEnumerable< char >  characters 
)
inlinestatic

Removes all occurrences of a specific set of characters from a string.

◆ StripFromEnd()

static string NanoByte.Common.StringUtils.StripFromEnd ( this string  value,
int  count 
)
inlinestatic

Returns a string with count characters removed from the end.


The documentation for this class was generated from the following file: