Show / Hide Table of Contents

Class StringUtils

Provides additional or simplified string functions.

Inheritance
Object
StringUtils
Namespace: NanoByte.Common
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
Type Description
Boolean

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
Type Description
Boolean

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
Type Name Description
String value
String searchFor
String rest
Returns
Type Description
Boolean

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
Type Name Description
String value
String searchFor
Returns
Type Description
Boolean

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
Type Name Description
String s1
String s2
Returns
Type Description
Boolean

EqualsIgnoreCase(Char, Char)

Compares chars using case-insensitive comparison.

Declaration
public static bool EqualsIgnoreCase(char c1, char c2)
Parameters
Type Name Description
Char c1
Char c2
Returns
Type Description
Boolean

EqualsIgnoreCase(String, String)

Compares strings using case-insensitive comparison.

Declaration
public static bool EqualsIgnoreCase(string s1, string s2)
Parameters
Type Name Description
String s1
String s2
Returns
Type Description
Boolean

FormatBytes(Int64, IFormatProvider)

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
Type Description
String

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
Type Description
String

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
Char searchFor
Returns
Type Description
String

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
Type Name Description
String value
String searchFor
Returns
Type Description
String

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
Char searchFor
Returns
Type Description
String

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
Type Name Description
String value
String searchFor
Returns
Type Description
String

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
Char searchFor
Returns
Type Description
String

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
Type Name Description
String value
String searchFor
Returns
Type Description
String

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
Char searchFor
Returns
Type Description
String

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
Type Name Description
String value
String searchFor
Returns
Type Description
String

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
Type Description
String

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
Type Name Description
String value
IEnumerable<Char> characters
Returns
Type Description
String

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
Type Description
String[]

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
Type Name Description
String value
String searchFor
String rest
Returns
Type Description
Boolean

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
Type Name Description
String value
String searchFor
Returns
Type Description
Boolean

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
Type Name Description
String value
Int32 maxLength
Returns
Type Description
String
In This Article
Back to top Copyright Bastian Eicher