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

Decodes a base16 (hexadecimal) to a byte array.

◆ Base16Encode()

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

Encodes a byte array in base16 (hexadecimal).

◆ Base32Encode()

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

Encodes a byte array in base32 without padding.

◆ Base64Utf8Decode()

static string NanoByte.Common.StringUtils.Base64Utf8Decode ( [NotNull] 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 ( [NotNull] this string  value)
inlinestatic

Encodes a string as UTF-8 in base64.

◆ ContainsIgnoreCase()

static bool NanoByte.Common.StringUtils.ContainsIgnoreCase ( [NotNull] this string  value,
[NotNull] 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 ( [NotNull] this string  value)
inlinestatic

Checks whether a string contains any whitespace characters

◆ CountOccurrences()

static int NanoByte.Common.StringUtils.CountOccurrences ( [CanBeNull] 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 ( [NotNull] this string  text,
[NotNull] string  value 
)
inlinestatic

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

◆ EqualsEmptyNull()

static bool NanoByte.Common.StringUtils.EqualsEmptyNull ( [CanBeNull] string  s1,
[CanBeNull] 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 ( [CanBeNull] string  s1,
[CanBeNull] string  s2 
)
static

Compare strings using case-insensitive comparison.

◆ EqualsIgnoreCase() [2/2]

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

Compare chars using case-insensitive comparison.

◆ EscapeArgument()

static string NanoByte.Common.StringUtils.EscapeArgument ( [NotNull] 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,
[CanBeNull] 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 ( [NotNull] this string  value,
[NotNull] string  str 
)
inlinestatic

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

◆ GetLeftPartAtFirstOccurrence() [2/2]

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

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

◆ GetLeftPartAtLastOccurrence() [1/2]

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

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

◆ GetLeftPartAtLastOccurrence() [2/2]

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

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

◆ GetRightPartAtFirstOccurrence() [1/2]

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

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

◆ GetRightPartAtFirstOccurrence() [2/2]

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

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

◆ GetRightPartAtLastOccurrence() [1/2]

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

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

◆ GetRightPartAtLastOccurrence() [2/2]

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

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

◆ Hash()

static string NanoByte.Common.StringUtils.Hash ( [NotNull] this string  value,
[NotNull] 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 ( [NotNull] string  separator,
[NotNull, ItemNotNull] 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 ( [NotNull, ItemNotNull] 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 ( [NotNull] 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 ( [NotNull] this string  text,
[NotNull] string  value 
)
inlinestatic

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

◆ StripCharacters()

static string NanoByte.Common.StringUtils.StripCharacters ( [CanBeNull] this string  value,
[NotNull] IEnumerable< char >  characters 
)
inlinestatic

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

◆ StripFromEnd()

static string NanoByte.Common.StringUtils.StripFromEnd ( [NotNull] 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: