Class StringEx
Class containing some extension methods for System.String.
Inheritance
Inherited Members
Namespace:Extend
Assembly:Extend.dll
Syntax
public static class StringEx
Methods
| Improve this Doc View SourceAppendWithNewLineIfNotEmpty(String, String, String)
Appends the given text to the string. Adds a newline before append, if target is not null.
Declaration
public static string AppendWithNewLineIfNotEmpty(this string target, string append, string newLine = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | target | The string to append to. |
| System.String | append | The string to append. |
| System.String | newLine | The new line string to use. |
Returns
| Type | Description |
|---|---|
| System.String | Returns the concatenated string. |
ChangeType(String, Type)
Returns an object of the specified type and whose value is equivalent to the specified object.
Declaration
public static object ChangeType(this string value, Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | An object that implements the System.IConvertible interface. |
| System.Type | type | The type of object to return. |
Returns
| Type | Description |
|---|---|
| System.Object | An object whose type is conversionType and whose value is equivalent to value.-or-A null reference (Nothing in Visual Basic), if value is null and conversionType is not a value type. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | type can not be null. |
| System.OverflowException | value represents a number that is out of the range of conversionType. |
| System.FormatException | value is not in a format recognized by conversionType. |
| System.InvalidCastException | This conversion is not supported. -or-value is null and conversionType is a value type.-or-value does not implement the System.IConvertible interface. |
ChangeType(String, Type, IFormatProvider)
Returns an object of the specified type and whose value is equivalent to the specified object.
Declaration
public static object ChangeType(this string value, Type type, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | An object that implements the System.IConvertible interface. |
| System.Type | type | The type of object to return. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information. |
Returns
| Type | Description |
|---|---|
| System.Object | An object whose type is conversionType and whose value is equivalent to value.-or-A null reference (Nothing in Visual Basic), if value is null and conversionType is not a value type. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | type can not be null. |
| System.ArgumentNullException | formatProvider can not be null. |
| System.OverflowException | value represents a number that is out of the range of conversionType. |
| System.FormatException | value is not in a format recognized by conversionType. |
| System.InvalidCastException | This conversion is not supported. -or-value is null and conversionType is a value type.-or-value does not implement the System.IConvertible interface. |
ChangeType<T>(String)
Returns an object of the specified type and whose value is equivalent to the specified object.
Declaration
public static T ChangeType<T>(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | An object that implements the System.IConvertible interface. |
Returns
| Type | Description |
|---|---|
| T | An object whose type is conversionType and whose value is equivalent to value.-or-A null reference (Nothing in Visual Basic), if value is null and conversionType is not a value type. |
Type Parameters
| Name | Description |
|---|---|
| T | The target type. |
Exceptions
| Type | Condition |
|---|---|
| System.OverflowException | value represents a number that is out of the range of conversionType. |
| System.FormatException | value is not in a format recognized by conversionType. |
| System.InvalidCastException | This conversion is not supported. -or-value is null and conversionType is a value type.-or-value does not implement the System.IConvertible interface. |
ChangeType<T>(String, IFormatProvider)
Returns an object of the specified type and whose value is equivalent to the specified object.
Declaration
public static T ChangeType<T>(this string value, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | An object that implements the System.IConvertible interface. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information. |
Returns
| Type | Description |
|---|---|
| T | An object whose type is conversionType and whose value is equivalent to value.-or-A null reference (Nothing in Visual Basic), if value is null and conversionType is not a value type. |
Type Parameters
| Name | Description |
|---|---|
| T | The target type. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | type can not be null. |
| System.ArgumentNullException | formatProvider can not be null. |
| System.OverflowException | value represents a number that is out of the range of conversionType. |
| System.FormatException | value is not in a format recognized by conversionType. |
| System.InvalidCastException | This conversion is not supported. -or-value is null and conversionType is a value type.-or-value does not implement the System.IConvertible interface. |
CharAt(String, Int32)
Gets the character of the given string at the specified position.
Declaration
public static char CharAt(this string value, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string. |
| System.Int32 | index | The index. |
Returns
| Type | Description |
|---|---|
| System.Char | Returns the character at the specified position. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | The given index is out of range. |
CompareOrdinal(String, String)
Compares the given strings using System.StringComparison.Ordinal.
Declaration
public static bool CompareOrdinal(this string value, string compareValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The first string to compare. |
| System.String | compareValue | The second string to compare. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the given strings are equals, otherwise false. |
CompareOrdinalIgnoreCase(String, String)
Compares the given strings using System.StringComparison.OrdinalIgnoreCase.
Declaration
public static bool CompareOrdinalIgnoreCase(this string value, string compareValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The first string to compare. |
| System.String | compareValue | The second string to compare. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the given strings are equals, otherwise false. |
ConcatAll(Object[])
Concatenates all given values.
Declaration
public static string ConcatAll(this object[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object[] | values | All values to concatenate. |
Returns
| Type | Description |
|---|---|
| System.String | The concatenation of all values. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | values can not be null. |
ConcatAll(String, Object[])
Concatenates all given values.
Declaration
public static string ConcatAll(this string str, params object[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The first string to concatenate. |
| System.Object[] | values | All values to concatenate. |
Returns
| Type | Description |
|---|---|
| System.String | The concatenation of all values. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | values can not be null. |
ConcatAll(String, String[])
Concatenates all given strings.
Declaration
public static string ConcatAll(this string str, params string[] strings)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The first string to concatenate. |
| System.String[] | strings | All strings to concatenate. |
Returns
| Type | Description |
|---|---|
| System.String | The concatenation of all strings. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | strings can not be null. |
ConcatAll(String[])
Concatenates all given strings.
Declaration
public static string ConcatAll(this string[] strings)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String[] | strings | All strings to concatenate. |
Returns
| Type | Description |
|---|---|
| System.String | The concatenation of all strings. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | strings can not be null. |
Contains(String, String, StringComparison)
Checks whether a specified substring occurs within the given string, or not.
Declaration
public static bool Contains(this string s, string value, StringComparison stringComparison)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The string to search in. |
| System.String | value | The string to seek. |
| System.StringComparison | stringComparison | One of the enumeration values that specifies the rules for the search. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the value parameter occurs within the given string; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | comparisonType is not a valid System.StringComparison value. |
| System.ArgumentNullException | s can not be null. |
| System.ArgumentNullException | value can not be null. |
ContainsAll(String, String[])
Checks if the string contains all values given.
Declaration
public static bool ContainsAll(this string s, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The string to check. |
| System.String[] | values | A list of string values. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the string contains all values, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | The values can not be null. |
ContainsAll(String, StringComparison, String[])
Checks if the string contains all values given.
Declaration
public static bool ContainsAll(this string s, StringComparison comparisonType, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The string to check. |
| System.StringComparison | comparisonType | Type of the comparison. |
| System.String[] | values | A list of string values. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the string contains all values, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | The values can not be null. |
ContainsAny(String, String[])
Checks if the string contains any of the values given.
Declaration
public static bool ContainsAny(this string str, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to check. |
| System.String[] | values | The values to search for. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the string contains any of the values given, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | The values can not be null. |
ContainsAny(String, StringComparison, String[])
Checks if the string contains any of the values given.
Declaration
public static bool ContainsAny(this string str, StringComparison comparisonType, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to check. |
| System.StringComparison | comparisonType | The string comparison type. |
| System.String[] | values | The values to search for. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the string contains any of the values given, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | The values can not be null. |
Extract(String, Func<Char, Boolean>)
Extracts parts of the input string, based on the predicate given.
Declaration
public static string Extract(this string str, Func<char, bool> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to extract. |
| System.Func<T, TResult><System.Char, System.Boolean> | predicate | The predicate. |
Returns
| Type | Description |
|---|---|
| System.String | The extracted parts of the input string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | The predicate can not be null. |
ExtractAllDecimal(String, Int32)
Extracts all Decimals from the given string.
Declaration
public static List<decimal> ExtractAllDecimal(this string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to extract the decimals from. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<T><System.Decimal> | The extracted decimals. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentOutOfRangeException | Invalid start index. |
ExtractAllDouble(String, Int32)
Extracts all Doubles from the given string.
Declaration
public static List<double> ExtractAllDouble(this string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to extract the doubles from. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<T><System.Double> | The extracted doubles. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentOutOfRangeException | Invalid start index. |
ExtractAllInt16(String, Int32)
Extracts all Int16 from the given string.
Declaration
public static List<short> ExtractAllInt16(this string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to extract the decimal from. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<T><System.Int16> | The extracted Int16. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentOutOfRangeException | Invalid start index. |
ExtractAllInt32(String, Int32)
Extracts all Int32 from the given string.
Declaration
public static List<int> ExtractAllInt32(this string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to extract the decimal from. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<T><System.Int32> | The extracted Int32. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentOutOfRangeException | Invalid start index. |
ExtractAllInt64(String, Int32)
Extracts all Int64 from the given string.
Declaration
public static List<long> ExtractAllInt64(this string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to extract the decimal from. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<T><System.Int64> | The extracted Int64. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentOutOfRangeException | Invalid start index. |
ExtractFirstDecimal(String, Int32)
Extracts the first Decimal from the given string.
Declaration
public static decimal ExtractFirstDecimal(this string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to extract the decimal from. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The extracted decimal. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentOutOfRangeException | Invalid start index. |
ExtractFirstDouble(String, Int32)
Extracts the first double from the given string.
Declaration
public static double ExtractFirstDouble(this string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to extract the decimal from. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.Double | The extracted double. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentOutOfRangeException | Invalid start index. |
ExtractFirstInt16(String, Int32)
Extracts the first Int16 from the given string.
Declaration
public static short ExtractFirstInt16(this string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to extract the decimal from. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.Int16 | The extracted Int16. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentOutOfRangeException | Invalid start index. |
ExtractFirstInt32(String, Int32)
Extracts the first Int32 from the given string.
Declaration
public static int ExtractFirstInt32(this string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to extract the decimal from. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The extracted Int32. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentOutOfRangeException | Invalid start index. |
ExtractFirstInt64(String, Int32)
Extracts the first Int64 from the given string.
Declaration
public static long ExtractFirstInt64(this string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to extract the decimal from. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.Int64 | The extracted Int64. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentOutOfRangeException | Invalid start index. |
ExtractLetters(String)
Extracts all letters of the input string.
Declaration
public static string ExtractLetters(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to extract the letters from. |
Returns
| Type | Description |
|---|---|
| System.String | The extracted letters. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
ExtractNumbers(String)
Extracts all numbers of the input string.
Declaration
public static string ExtractNumbers(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to extract the numbers from. |
Returns
| Type | Description |
|---|---|
| System.String | The extracted numbers. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
F(String, IFormatProvider, Object[])
Replaces the format item in a specified System.String with the System.String representation of a corresponding System.Object in a specified array.
Declaration
public static string F(this string format, IFormatProvider formatProvider, params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | format | The System.String containing the format items. |
| System.IFormatProvider | formatProvider | The format provider. |
| System.Object[] | args | The array containing all the corresponding values. |
Returns
| Type | Description |
|---|---|
| System.String | A copy of format in which the format items have been replaced by the System.String representation of the corresponding objects in args. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The format string can not be null. |
| System.ArgumentNullException | The arguments can not be null. |
| System.FormatException | Format is invalid.-or- The index of a format item is less than zero, or greater than or equal to the length of the args array. |
F(String, Object[])
Replaces the format item in a specified System.String with the System.String representation of a corresponding System.Object in a specified array.
Declaration
public static string F(this string format, params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | format | The System.String containing the format items. |
| System.Object[] | args | The array containing all the corresponding values. |
Returns
| Type | Description |
|---|---|
| System.String | A copy of format in which the format items have been replaced by the System.String representation of the corresponding objects in args. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The format string can not be null. |
| System.ArgumentNullException | The arguments can not be null. |
| System.FormatException | Format is invalid.-or- The index of a format item is less than zero, or greater than or equal to the length of the args array. |
FormatFileExtension(String)
Formats the given file extension.
Declaration
public static string FormatFileExtension(this string fileExtension)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | fileExtension | The file extension to format. |
Returns
| Type | Description |
|---|---|
| System.String | The correct formatted file extension. |
Remarks
Formatted extension will have the following format: ".txt".
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The file extension can not be null. |
| System.ArgumentException | Can not format a empty string to a file extension. |
GetAfter(String, Char, Int32)
Gets the part of the string after the specified value, starting at the given start index.
Declaration
public static string GetAfter(this string s, char value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.Char | value | The value to search. |
| System.Int32 | startIndex | The start index of the substring. |
Returns
| Type | Description |
|---|---|
| System.String | The string after the specified value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentOutOfRangeException | The specified start index is invalid. |
GetAfter(String, Char, Int32, Int32)
Gets the part of the string after the specified value, starting at the given start index and ending after the specified number of characters.
Declaration
public static string GetAfter(this string s, char value, int startIndex, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.Char | value | The value to search. |
| System.Int32 | startIndex | The start index of the string. |
| System.Int32 | length | The length of the string, from the start index. |
Returns
| Type | Description |
|---|---|
| System.String | The string after the specified value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentOutOfRangeException | The specified range is invalid. |
GetAfter(String, String, Int32)
Gets the part of the string after the specified value, starting at the given start index.
Declaration
public static string GetAfter(this string s, string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.String | value | The value to search. |
| System.Int32 | startIndex | The start index of the substring. |
Returns
| Type | Description |
|---|---|
| System.String | The string after the specified value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | s can not be null. |
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | The specified start index is invalid. |
GetAfter(String, String, Int32, Int32)
Gets the part of the string after the specified value, starting at the given start index and ending after the specified number of characters.
Declaration
public static string GetAfter(this string s, string value, int startIndex, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.String | value | The value to search. |
| System.Int32 | startIndex | The start index of the string. |
| System.Int32 | length | The length of the string, from the start index. |
Returns
| Type | Description |
|---|---|
| System.String | The string after the specified value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | The specified range is invalid. |
GetBefore(String, Char, Int32)
Gets the part of the string before the specified value, starting at the given start index.
Declaration
public static string GetBefore(this string s, char value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.Char | value | The value to search for. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.String | The part of the string before the specified value, starting at the given start index. Or an empty string if the given string doesn't contain the given value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentOutOfRangeException | The specified start index is invalid. |
GetBefore(String, Char, Int32, Int32)
Gets the part of the string before the specified value, starting at the given start index and ending after the specified number of characters.
Declaration
public static string GetBefore(this string s, char value, int startIndex, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.Char | value | The value to search for. |
| System.Int32 | startIndex | The start index of the string. |
| System.Int32 | length | The length of the string, from the start index. |
Returns
| Type | Description |
|---|---|
| System.String | The part of the string before the specified value, starting at the given start index. Or an empty string if the given string doesn't contain the given value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentOutOfRangeException | The specified range is invalid. |
GetBefore(String, String, Int32)
Gets the part of the string before the specified value, starting at the given start index.
Declaration
public static string GetBefore(this string s, string value, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.String | value | The value to search for. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.String | The part of the string before the specified value, starting at the given start index. Or an empty string if the given string doesn't contain the given value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | The specified start index is invalid. |
GetBefore(String, String, Int32, Int32)
Gets the part of the string before the specified value, starting at the given start index and ending after the specified number of characters.
Declaration
public static string GetBefore(this string s, string value, int startIndex, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.String | value | The value to search for. |
| System.Int32 | startIndex | The start index of the string. |
| System.Int32 | length | The length of the string, from the start index. |
Returns
| Type | Description |
|---|---|
| System.String | The part of the string before the specified value, starting at the given start index. Or an empty string if the given string doesn't contain the given value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | The specified range is invalid. |
GetBetween(String, Char, Char, Int32)
Gets the part of the input string between the before and after value, starting at the given start index.
Declaration
public static string GetBetween(this string s, char before, char after, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.Char | before | The before value. |
| System.Char | after | The after value. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.String | The part of the string between the before and after value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | The specified start index is invalid. |
GetBetween(String, Char, Char, Int32, Int32)
Gets the part of the input string between the before and after value, starting at the given start index, and ending after the specified number of characters.
Declaration
public static string GetBetween(this string s, char before, char after, int startIndex, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.Char | before | The before value. |
| System.Char | after | The after value. |
| System.Int32 | startIndex | The start index of the string. |
| System.Int32 | length | The length of the string, from the start index. |
Returns
| Type | Description |
|---|---|
| System.String | The part of the string between the before and after value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | The specified range is invalid. |
GetBetween(String, String, String, Int32)
Gets the part of the input string between the before and after value, starting at the given start index.
Declaration
public static string GetBetween(this string s, string before, string after, int startIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.String | before | The before value. |
| System.String | after | The after value. |
| System.Int32 | startIndex | The start index of the string. |
Returns
| Type | Description |
|---|---|
| System.String | The part of the string between the before and after value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | The specified start index is invalid. |
GetBetween(String, String, String, Int32, Int32)
Gets the part of the input string between the before and after value, starting at the given start index, and ending after the specified number of characters.
Declaration
public static string GetBetween(this string s, string before, string after, int startIndex, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.String | before | The before value. |
| System.String | after | The after value. |
| System.Int32 | startIndex | The start index of the string. |
| System.Int32 | length | The length of the string, from the start index. |
Returns
| Type | Description |
|---|---|
| System.String | The part of the string between the before and after value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | The specified range is invalid. |
GetFileExtension(String)
Gets the extension of the given file.
Declaration
public static string GetFileExtension(this string fileName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | fileName | The name of the file. |
Returns
| Type | Description |
|---|---|
| System.String | The file extension. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The file name can not be null. |
GetLines(String)
Enumerates all lines in the given string.
Declaration
public static IEnumerable<string> GetLines(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string whose lines are to be enumerated. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T><System.String> | An enumerable sequence of lines in this string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | value can not be null. |
IfNotEmpty(String, String)
Returns the input value if it's not empty, otherwise the alternative value.
Declaration
public static string IfNotEmpty(this string value, string alternativeValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The input string. |
| System.String | alternativeValue | The alternative value. |
Returns
| Type | Description |
|---|---|
| System.String | The input or the alternative value. |
IsAlpha(String)
Checks if the string is alpha.
Declaration
public static bool IsAlpha(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the string is alpha only, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
IsAlphaNumeric(String)
Checks if the string is alpha numeric.
Declaration
public static bool IsAlphaNumeric(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the string is alpha numeric, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
IsEmpty(String)
Gets whether the given System.String is empty or not.
Declaration
public static bool IsEmpty(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The System.String to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value of true if the given System.String is empty, otherwise false. |
IsMatch(String, String)
Gets whether a System.Text.RegularExpressions.Regex with the specified pattern finds a match in the specified input
System.String.
Declaration
public static bool IsMatch(this string input, string pattern)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The System.String to search for a match. |
| System.String | pattern | The regular expression pattern used by the System.Text.RegularExpressions.Regex. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value of true if the regular expression finds a match, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The input can not be null. |
| System.ArgumentNullException | The pattern can not be null. |
IsMatch(String, String, RegexOptions)
Gets whether a System.Text.RegularExpressions.Regex with the specified pattern finds a match in the specified input
System.String.
Declaration
public static bool IsMatch(this string input, string pattern, RegexOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The System.String to search for a match. |
| System.String | pattern | The regular expression pattern used by the System.Text.RegularExpressions.Regex. |
| System.Text.RegularExpressions.RegexOptions | options | The regular expression options used by the System.Text.RegularExpressions.Regex. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value of true if the regular expression finds a match, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The input can not be null. |
| System.ArgumentNullException | The pattern can not be null. |
IsMatch(String, String, RegexOptions, TimeSpan)
Gets whether a System.Text.RegularExpressions.Regex with the specified pattern finds a match in the specified input
System.String.
Declaration
public static bool IsMatch(this string input, string pattern, RegexOptions options, TimeSpan timeOut)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The System.String to search for a match. |
| System.String | pattern | The regular expression pattern used by the System.Text.RegularExpressions.Regex. |
| System.Text.RegularExpressions.RegexOptions | options | The regular expression options used by the System.Text.RegularExpressions.Regex. |
| System.TimeSpan | timeOut | The timeout for the match operation. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value of true if the regular expression finds a match, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The input can not be null. |
| System.ArgumentNullException | The pattern can not be null. |
IsNotEmpty(String)
Gets whether the given System.String is empty or not.
Declaration
public static bool IsNotEmpty(this string input)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The System.String to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value of true if the given System.String is not empty, otherwise false. |
IsNotMatch(String, String)
Gets whether a with the specified pattern finds not a match in the specified input System.String.
Declaration
public static bool IsNotMatch(this string input, string pattern)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The System.String to search for a match. |
| System.String | pattern | The regular expression pattern used by the System.Text.RegularExpressions.Regex. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value of true if the regular expression doesn't find a match, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The input can not be null. |
| System.ArgumentNullException | The pattern can not be null. |
IsNotMatch(String, String, RegexOptions)
Gets whether a System.Text.RegularExpressions.Regex with the specified pattern finds not a match in the specified input
System.String.
Declaration
public static bool IsNotMatch(this string input, string pattern, RegexOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The System.String to search for a match. |
| System.String | pattern | The regular expression pattern used by the System.Text.RegularExpressions.Regex. |
| System.Text.RegularExpressions.RegexOptions | options | The regular expression options used by the System.Text.RegularExpressions.Regex. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value of true if the regular expression doesn't find a match, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The input can not be null. |
| System.ArgumentNullException | The pattern can not be null. |
IsNotMatch(String, String, RegexOptions, TimeSpan)
Gets whether a System.Text.RegularExpressions.Regex with the specified pattern finds not a match in the specified input
System.String.
Declaration
public static bool IsNotMatch(this string input, string pattern, RegexOptions options, TimeSpan timeOut)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The System.String to search for a match. |
| System.String | pattern | The regular expression pattern used by the System.Text.RegularExpressions.Regex. |
| System.Text.RegularExpressions.RegexOptions | options | The regular expression options used by the System.Text.RegularExpressions.Regex. |
| System.TimeSpan | timeOut | The timeout for the match operation. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value of true if the regular expression doesn't find a match, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The input can not be null. |
| System.ArgumentNullException | The pattern can not be null. |
IsNumeric(String)
Checks if the string is numeric.
Declaration
public static bool IsNumeric(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the string is numeric only, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
Join(String, Object[])
Concatenates all the elements of a object array, using the specified separator between each element.
Declaration
public static string Join(this string separator, object[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | separator | The string to use as a separator. Is included in the returned string only if it has more than one element. |
| System.Object[] | values | An array that contains the elements to concatenate. |
Returns
| Type | Description |
|---|---|
| System.String | A string that consists of the elements in delimited by the string. If is an empty array, the method returns String.Empty. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The values can not be null. |
Join(String, String[])
Concatenates all the elements of a string array, using the specified separator between each element.
Declaration
public static string Join(this string separator, string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | separator | The string to use as a separator. Is included in the returned string only if it has more than one element. |
| System.String[] | values | An array that contains the elements to concatenate. |
Returns
| Type | Description |
|---|---|
| System.String | A string that consists of the elements in delimited by the string. If is an empty array, the method returns String.Empty. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The values can not be null. |
Join(String, String[], Int32, Int32)
Concatenates all the elements of a string array, using the specified separator between each element.
Declaration
public static string Join(this string separator, string[] values, int startIndex, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | separator | The string to use as a separator. Is included in the returned string only if it has more than one element. |
| System.String[] | values | An array that contains the elements to concatenate. |
| System.Int32 | startIndex | The first element in to use. |
| System.Int32 | count | The number of elements of to use. |
Returns
| Type | Description |
|---|---|
| System.String | A string that consists of the elements in delimited by the string. If is an empty array, the method returns String.Empty. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The values can not be null. |
Join<T>(String, IEnumerable<T>)
Concatenates all the elements of a IEnumerable, using the specified separator between each element.
Declaration
public static string Join<T>(this string separator, IEnumerable<T> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | separator | The string to use as a separator. Is included in the returned string only if it has more than one element. |
| System.Collections.Generic.IEnumerable<T><T> | values | An IEnumerable that contains the elements to concatenate. |
Returns
| Type | Description |
|---|---|
| System.String | A string that consists of the elements in delimited by the string. If is an empty IEnumerable, the method returns String.Empty. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the IEnumerable. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The values can not be null. |
KeepLetters(String)
Removes all characters which aren't letters.
Declaration
public static string KeepLetters(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The input string. |
Returns
| Type | Description |
|---|---|
| System.String | A new string containing the letters of the input string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
KeepLettersAndNumbers(String)
Removes all characters which aren't letters or numbers.
Declaration
public static string KeepLettersAndNumbers(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The input string. |
Returns
| Type | Description |
|---|---|
| System.String | A new string containing the letters and numbers of the input string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
KeepNumbers(String)
Removes all characters which aren't numbers.
Declaration
public static string KeepNumbers(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The input string. |
Returns
| Type | Description |
|---|---|
| System.String | A new string containing the numbers of the input string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
KeepWhere(String, Func<Char, Boolean>)
Returns a string which only contains the characters matching the given predicate.
Declaration
public static string KeepWhere(this string str, Func<char, bool> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The input string. |
| System.Func<T, TResult><System.Char, System.Boolean> | predicate | The predicate. |
Returns
| Type | Description |
|---|---|
| System.String | Returns a string which only contains the characters matching the given predicate. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | The predicate can not be null. |
Left(String, Int32)
Returns a string containing a specified number of characters from the left side of a string.
Declaration
public static string Left(this string value, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string from which the leftmost characters are returned. |
| System.Int32 | count | The number of characters to return. |
Returns
| Type | Description |
|---|---|
| System.String | Returns a string containing a specified number of characters from the left side of the given string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | count is less than 0 or greater than the length of the given string. |
Match(String, String)
Searches the specified input string for the first occurrence of the specified regular expression.
Declaration
public static Match Match(this string input, string pattern)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The string to search for a match. |
| System.String | pattern | The regular expression pattern to match. |
Returns
| Type | Description |
|---|---|
| System.Text.RegularExpressions.Match | An object that contains information about the match. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | input can not be null. |
| System.ArgumentNullException | pattern can not be null. |
Match(String, String, RegexOptions)
Searches the input string for the first occurrence of the specified regular expression, using the specified matching options.
Declaration
public static Match Match(this string input, string pattern, RegexOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The string to search for a match. |
| System.String | pattern | The regular expression pattern to match. |
| System.Text.RegularExpressions.RegexOptions | options | A bitwise combination of the enumeration values that provide options for matching. |
Returns
| Type | Description |
|---|---|
| System.Text.RegularExpressions.Match | An object that contains information about the match. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | input can not be null. |
| System.ArgumentNullException | pattern can not be null. |
Match(String, String, RegexOptions, TimeSpan)
Searches the input string for the first occurrence of the specified regular expression, using the specified matching options.
Declaration
public static Match Match(this string input, string pattern, RegexOptions options, TimeSpan timeOut)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The string to search for a match. |
| System.String | pattern | The regular expression pattern to match. |
| System.Text.RegularExpressions.RegexOptions | options | A bitwise combination of the enumeration values that provide options for matching. |
| System.TimeSpan | timeOut | The timeout for the regular expression operation. |
Returns
| Type | Description |
|---|---|
| System.Text.RegularExpressions.Match | An object that contains information about the match. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | input can not be null. |
| System.ArgumentNullException | pattern can not be null. |
Matches(String, String)
Searches the specified input string for all occurrences of a specified regular expression.
Declaration
public static MatchCollection Matches(this string input, string pattern)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The string to search for a match. |
| System.String | pattern | The regular expression pattern to match. |
Returns
| Type | Description |
|---|---|
| System.Text.RegularExpressions.MatchCollection | A collection of the objects found by the search. If no matches are found, the method returns an empty collection object. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | input can not be null. |
| System.ArgumentNullException | pattern can not be null. |
Matches(String, String, RegexOptions)
Searches the specified input string for all occurrences of a specified regular expression, using the specified matching options.
Declaration
public static MatchCollection Matches(this string input, string pattern, RegexOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The string to search for a match. |
| System.String | pattern | The regular expression pattern to match. |
| System.Text.RegularExpressions.RegexOptions | options | A bitwise combination of the enumeration values that specify options for matching. |
Returns
| Type | Description |
|---|---|
| System.Text.RegularExpressions.MatchCollection | A collection of the objects found by the search. If no matches are found, the method returns an empty collection object. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | input can not be null. |
| System.ArgumentNullException | pattern can not be null. |
Matches(String, String, RegexOptions, TimeSpan)
Searches the specified input string for all occurrences of a specified regular expression, using the specified matching options.
Declaration
public static MatchCollection Matches(this string input, string pattern, RegexOptions options, TimeSpan timeOut)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The string to search for a match. |
| System.String | pattern | The regular expression pattern to match. |
| System.Text.RegularExpressions.RegexOptions | options | A bitwise combination of the enumeration values that specify options for matching. |
| System.TimeSpan | timeOut | The timeout for the regular expression operation. |
Returns
| Type | Description |
|---|---|
| System.Text.RegularExpressions.MatchCollection | A collection of the objects found by the search. If no matches are found, the method returns an empty collection object. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | input can not be null. |
| System.ArgumentNullException | pattern can not be null. |
RemoveLetters(String)
Removes all letters from the given string.
Declaration
public static string RemoveLetters(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The input string. |
Returns
| Type | Description |
|---|---|
| System.String | The given string without any letters. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
RemoveLettersAndNumbers(String)
Removes all letters and numbers from the given string.
Declaration
public static string RemoveLettersAndNumbers(this string s)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
Returns
| Type | Description |
|---|---|
| System.String | The given string without any letters or numbers. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | s can not be null. |
RemoveNumbers(String)
Removes all numbers from the given string.
Declaration
public static string RemoveNumbers(this string s)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
Returns
| Type | Description |
|---|---|
| System.String | The given string without any numbers. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | s can not be null. |
RemoveWhere(String, Func<Char, Boolean>)
Removes some characters from the given string, based on the predicate specified.
Declaration
public static string RemoveWhere(this string s, Func<char, bool> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.Func<T, TResult><System.Char, System.Boolean> | predicate | The predicate. |
Returns
| Type | Description |
|---|---|
| System.String | Returns the input string without any of the removed characters. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | s can not be null. |
| System.ArgumentNullException | predicate can not be null. |
Repeat(String, Int32)
Repeats the given string a specified number of times.
Declaration
public static string Repeat(this string s, int repeatCount)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.Int32 | repeatCount | The number of repeats. |
Returns
| Type | Description |
|---|---|
| System.String | Returns the repeated string. |
ReplaceAt(String, Int32, Char)
Replaces a single character at the specified position with the specified replacement character.
Declaration
public static string ReplaceAt(this string value, int index, char replace)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string in which a character will be replaced. |
| System.Int32 | index | The position of the character to replace. |
| System.Char | replace | The replacement character. |
Returns
| Type | Description |
|---|---|
| System.String | Returns the string with the replaced character. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | index doesn't refer to a valid position within the string. |
ReplaceByEmpty(String, String[])
Replace all given values by an empty string.
Declaration
public static string ReplaceByEmpty(this string s, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The input string. |
| System.String[] | values | A list of all values to replace. |
Returns
| Type | Description |
|---|---|
| System.String | Returns a string with all specified values replaced by an empty string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | s can not be null. |
| System.ArgumentNullException | values can not be null. |
Reverse(String)
Reverses the given string.
Declaration
public static string Reverse(this string s)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The string to reverse. |
Returns
| Type | Description |
|---|---|
| System.String | Returns the reversed string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
Right(String, Int32)
Returns a string containing a specified number of characters from the right side of a string.
Declaration
public static string Right(this string value, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string from which the rightmost characters are returned. |
| System.Int32 | count | The number of characters to return. |
Returns
| Type | Description |
|---|---|
| System.String | Returns a string containing a specified number of characters from the right side of a string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | count is less than 0 or greater than the length of the string. |
SafeToCultureInfo(String)
Tries to create a new System.Globalization.CultureInfo with the given name.
Declaration
public static CultureInfo SafeToCultureInfo(this string name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The name of the culture. |
Returns
| Type | Description |
|---|---|
| System.Globalization.CultureInfo | Returns the System.Globalization.CultureInfo with the given name, or null if the culture is not supported. |
SafeToCultureInfo(String, CultureInfo)
Tries to create a new System.Globalization.CultureInfo with the given name.
Declaration
public static CultureInfo SafeToCultureInfo(this string name, CultureInfo fallbackCulture)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The name of the culture. |
| System.Globalization.CultureInfo | fallbackCulture | The culture returned if the culture with the given name is not supported. |
Returns
| Type | Description |
|---|---|
| System.Globalization.CultureInfo | Returns the System.Globalization.CultureInfo with the given name, or fallbackCulture. |
SaveToBoolean(String, Boolean)
Tries to convert the specified string representation of a logical value to its System.Boolean equivalent.
Declaration
public static bool SaveToBoolean(this string value, bool defaultValue = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing the value to convert. |
| System.Boolean | defaultValue | The default value, returned if the conversion fails. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns the converted value, or the given default value if the conversion failed. |
SaveToByte(String, Byte)
Tries to convert the string representation of a number to its System.Byte equivalent.
Declaration
public static byte SaveToByte(this string value, byte defaultValue = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string that contains a number to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer numberStyle. The string to pars. |
| System.Byte | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Byte | Returns the converted value, or the given default value if the conversion failed. |
SaveToByte(String, NumberStyles, IFormatProvider, Byte)
Tries to convert the string representation of a number to its System.Byte equivalent.
Declaration
public static byte SaveToByte(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, byte defaultValue = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string that contains a number to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer numberStyle. The string to pars. |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of enumeration values that indicates the numberStyle elements that can be present in s. A typical value to specify is System.Globalization.NumberStyles.Integer. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about s. If formatProvider is null, the thread current culture is used. |
| System.Byte | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Byte | Returns the converted value, or the given default value if the conversion failed. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formatProvider can not be null. |
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-style is not a combination of System.Globalization.NumberStyles.AllowHexSpecifier and System.Globalization.NumberStyles.HexNumber values. |
SaveToChar(String, Char)
Converts the value of the specified string to its equivalent Unicode character.
Declaration
public static char SaveToChar(this string value, char defaultValue = '\0')
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string that contains a single character. |
| System.Char | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Char | Returns the converted value, or the given default value if the conversion failed. |
SaveToDateTime(String, DateTime)
Converts the specified string representation of a date and time to its System.DateTime equivalent.
Declaration
public static DateTime SaveToDateTime(this string value, DateTime defaultValue = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A System.String containing a date and time to convert. |
| System.DateTime | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.DateTime | Returns the converted value, or the given default value if the conversion failed. |
SaveToDateTime(String, IFormatProvider, DateTimeStyles, DateTime)
Converts the specified string representation of a date and time to its System.DateTime equivalent using the specified culture-specific format information and formatting style.
Declaration
public static DateTime SaveToDateTime(this string value, IFormatProvider formatProvider, DateTimeStyles dateTimeStyle, DateTime defaultValue = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A System.Stringcontaining a date and time to convert. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about value. |
| System.Globalization.DateTimeStyles | dateTimeStyle | A bitwise combination of enumeration values that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is System.Globalization.DateTimeStyles.None. |
| System.DateTime | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.DateTime | Returns the converted value, or the given default value if the conversion failed. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The format provider can not be null. |
| System.ArgumentException | dateTimeStyle is not a valid System.Globalization.DateTimeStyles value.-or-styles contains an invalid combination of System.Globalization.DateTimeStyles values (for example, both System.Globalization.DateTimeStyles.AssumeLocal and System.Globalization.DateTimeStyles.AssumeUniversal). |
SaveToDecimal(String, Decimal)
Converts the string representation of a number to its System.Decimal equivalent.
Declaration
public static decimal SaveToDecimal(this string value, decimal defaultValue = 0M)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string representation of the number to convert. |
| System.Decimal | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Decimal | Returns the converted value, or the given default value if the conversion failed. |
SaveToDecimal(String, NumberStyles, IFormatProvider, Decimal)
Converts the string representation of a number to its System.Decimal equivalent using the specified numberStyle and culture-specific format.
Declaration
public static decimal SaveToDecimal(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, decimal defaultValue = 0M)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string representation of the number to convert. |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of enumeration values that indicates the permitted format of value. A typical value to specify is System.Globalization.NumberStyles.Number. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific parsing information about value. |
| System.Decimal | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Decimal | Returns the converted value, or the given default value if the conversion failed. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formatProvider can not be null. |
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-style is the System.Globalization.NumberStyles.AllowHexSpecifier value. |
SaveToDouble(String, Double)
Converts the string representation of a number to its double-precision floating-point number equivalent.
Declaration
public static double SaveToDouble(this string value, double defaultValue = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Double | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Double | Returns the converted value, or the given default value if the conversion failed. |
SaveToDouble(String, NumberStyles, IFormatProvider, Double)
Converts the string representation of a number in a specified numberStyle and culture-specific format to its double-precision floating-point number equivalent.
Declaration
public static double SaveToDouble(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, double defaultValue = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of System.Globalization.NumberStyles values that indicates the permitted format of value. A typical value to specify is System.Globalization.NumberStyles.Float combined with System.Globalization.NumberStyles.AllowThousands. |
| System.IFormatProvider | formatProvider | An System.IFormatProvider that supplies culture-specific formatting information about value. |
| System.Double | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Double | Returns the converted value, or the given default value if the conversion failed. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-numberStyle includes the System.Globalization.NumberStyles.AllowHexSpecifier value. |
| System.ArgumentNullException | formatProvider can not be null. |
SaveToGuid(String, Guid)
Converts the string representation of a GUID to the equivalent System.Guid structure.
Declaration
public static Guid SaveToGuid(this string value, Guid defaultValue = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
| System.Guid | defaultValue | The default value, returned if the parsing fails. If not provided default will be System.Guid.Empty. |
Returns
| Type | Description |
|---|---|
| System.Guid | Returns the converted value, or the given default value if the conversion failed. |
SaveToInt16(String, NumberStyles, IFormatProvider, Int16)
Converts the string representation of a number in a specified numberStyle and culture-specific format to its 16-bit signed integer equivalent.
Declaration
public static short SaveToInt16(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, short defaultValue = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of enumeration values that indicates the numberStyle elements that can be present in value. A typical value to specify is System.Globalization.NumberStyles.Integer. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about value. |
| System.Int16 | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Int16 | Returns the converted value, or the given default value if the conversion failed. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formatProvider can not be null. |
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-style is not a combination of System.Globalization.NumberStyles.AllowHexSpecifier and System.Globalization.NumberStyles.HexNumber values. |
SaveToInt16(String, Int16)
Converts the string representation of a number to its 16-bit signed integer equivalent.
Declaration
public static short SaveToInt16(this string value, short defaultValue = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Int16 | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Int16 | Returns the converted value, or the given default value if the conversion failed. |
SaveToInt32(String, NumberStyles, IFormatProvider, Int32)
Converts the string representation of a number in a specified numberStyle and culture-specific format to its 32-bit signed integer equivalent.
Declaration
public static int SaveToInt32(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, int defaultValue = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of enumeration values that indicates the numberStyle elements that can be present in value. A typical value to specify is System.Globalization.NumberStyles.Integer. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about value. |
| System.Int32 | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Int32 | Returns the converted value, or the given default value if the conversion failed. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formatProvider can not be null. |
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-style is not a combination of System.Globalization.NumberStyles.AllowHexSpecifier and System.Globalization.NumberStyles.HexNumber values. |
SaveToInt32(String, Int32)
Converts the string representation of a number to its 32-bit signed integer equivalent.
Declaration
public static int SaveToInt32(this string value, int defaultValue = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Int32 | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Int32 | Returns the converted value, or the given default value if the conversion failed. |
SaveToInt64(String, NumberStyles, IFormatProvider, Int64)
Converts the string representation of a number in a specified numberStyle and culture-specific format to its 64-bit signed integer equivalent.
Declaration
public static long SaveToInt64(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, long defaultValue = 0L)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of enumeration values that indicates the numberStyle elements that can be present in value. A typical value to specify is System.Globalization.NumberStyles.Integer. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about value. |
| System.Int64 | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Int64 | Returns the converted value, or the given default value if the conversion failed. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formatProvider can not be null. |
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-style is not a combination of System.Globalization.NumberStyles.AllowHexSpecifier and System.Globalization.NumberStyles.HexNumber values. |
SaveToInt64(String, Int64)
Converts the string representation of a number to its 64-bit signed integer equivalent.
Declaration
public static long SaveToInt64(this string value, long defaultValue = 0L)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Int64 | defaultValue | The default value, returned if the parsing fails. |
Returns
| Type | Description |
|---|---|
| System.Int64 | Returns the converted value, or the given default value if the conversion failed. |
Split(String, String, StringSplitOptions)
Returns a string array that contains the substrings in this string that are delimited by the given separator. A parameter specifies whether to return empty array elements.
Declaration
public static string[] Split(this string value, string separator, StringSplitOptions stringSplitOption = StringSplitOptions.None)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to split. |
| System.String | separator | A string that delimit the substrings in this string. |
| System.StringSplitOptions | stringSplitOption | System.StringSplitOptions.RemoveEmptyEntries to omit empty array elements from the array returned; or System.StringSplitOptions.None to include empty array elements in the array returned. |
Returns
| Type | Description |
|---|---|
| System.String[] | Returns an array whose elements contain the substrings in this string that are delimited by the separator. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | The separator can not be null. |
Split(String, StringSplitOptions, String[])
Returns a string array that contains the substrings in this string that are delimited by elements of a specified string array. A parameter specifies whether to return empty array elements.
Declaration
public static string[] Split(this string value, StringSplitOptions stringSplitOption, params string[] separators)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to split. |
| System.StringSplitOptions | stringSplitOption | System.StringSplitOptions.RemoveEmptyEntries to omit empty array elements from the array returned; or System.StringSplitOptions.None to include empty array elements in the array returned. |
| System.String[] | separators | An array of strings that delimit the substrings in this string, an empty array that contains no delimiters, or null. |
Returns
| Type | Description |
|---|---|
| System.String[] | Returns an array whose elements contain the substrings in this string that are delimited by one or more strings in separator. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
| System.ArgumentNullException | The separator can not be null. |
SplitLines(String)
Splits the given string at each line break (System.Environment.NewLine).
Declaration
public static string[] SplitLines(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to split. |
Returns
| Type | Description |
|---|---|
| System.String[] | Returns an array whose elements contain the substrings in this string that are delimited by System.Environment.NewLine. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | value can not be null. |
SplitLines(String, StringSplitOptions)
Splits the given string at each line break (System.Environment.NewLine).
Declaration
public static string[] SplitLines(this string value, StringSplitOptions stringSplitOptions)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to split. |
| System.StringSplitOptions | stringSplitOptions | System.StringSplitOptions.RemoveEmptyEntries to omit empty array elements from the array returned; or System.StringSplitOptions.None to include empty array elements in the array returned. |
Returns
| Type | Description |
|---|---|
| System.String[] | Returns an array whose elements contain the substrings in this string that are delimited by System.Environment.NewLine. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | value can not be null. |
SubstringLeft(String, Int32)
Returns the specified number of characters from the start of the string.
Declaration
public static string SubstringLeft(this string s, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The string to get the substring of. |
| System.Int32 | length | The number of characters. |
Returns
| Type | Description |
|---|---|
| System.String | Returns the specified number of characters from the start of the string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | s can not be null. |
SubstringLeftSafe(String, Int32)
Returns the specified number of characters from the start of the string. Checks if the given length is valid, if not it uses the length of the string.
Declaration
public static string SubstringLeftSafe(this string s, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The string to get the substring of. |
| System.Int32 | length | The number of characters. |
Returns
| Type | Description |
|---|---|
| System.String | Returns the specified number of characters from the start of the string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | s can not be null. |
SubstringLeftSafe(String, Int32, Int32)
Returns the specified number of characters from the start index. Checks if the given start index and length is valid, if not it uses the length of the string.
Declaration
public static string SubstringLeftSafe(this string s, int startIndex, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The string to get the substring of. |
| System.Int32 | startIndex | The start index. |
| System.Int32 | length | The number of characters. |
Returns
| Type | Description |
|---|---|
| System.String | Returns the specified number of characters from the start index of the string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | s can not be null. |
SubstringRight(String, Int32)
Returns the specified number of characters from the end of the string.
Declaration
public static string SubstringRight(this string str, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to get the substring of. |
| System.Int32 | length | The number of characters. |
Returns
| Type | Description |
|---|---|
| System.String | Returns the specified number of characters from the end of the string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
SubstringRightSafe(String, Int32)
Returns the specified number of characters from the end of the string. Checks if the given length is valid, if not it uses the length of the string.
Declaration
public static string SubstringRightSafe(this string str, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to get the substring of. |
| System.Int32 | length | The number of characters. |
Returns
| Type | Description |
|---|---|
| System.String | Returns the specified number of characters from the end of the string. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The string can not be null. |
TakeAndRemove(Int32, ref String)
Returns a specified number of characters from the start of the given value and removes the returned characters from the value.
Declaration
public static string TakeAndRemove(this int count, ref string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | count | The numbers of characters to return. |
| System.String | value | The source value. |
Returns
| Type | Description |
|---|---|
| System.String | A System.String that contains the specified number of chars. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | value can not be null. |
| System.ArgumentOutOfRangeException | Count must be smaller than the length of the given value. |
ToBoolean(String)
Converts the given string to a boolean.
Declaration
public static bool ToBoolean(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns the boolean. |
Remarks
The framework does not know a culture specific convert method, so does this library.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.FormatException | Value is not equal to System.Boolean.TrueString or System.Boolean.FalseString. |
ToByte(String)
Converts the given string to a byte.
Declaration
public static byte ToByte(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
Returns
| Type | Description |
|---|---|
| System.Byte | Returns a byte value that is equivalent to the number contained in value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.FormatException | The value is not of the correct format. |
| System.OverflowException | The value represents a number less than System.Byte.MinValue or greater than System.Byte.MaxValue. |
ToByte(String, IFormatProvider)
Converts the given string to a byte.
Declaration
public static byte ToByte(this string value, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
| System.IFormatProvider | formatProvider | The format provider. |
Returns
| Type | Description |
|---|---|
| System.Byte | Returns a byte value that is equivalent to the number contained in value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentNullException | The format provider can not be null. |
| System.FormatException | The value is not of the correct format. |
| System.OverflowException | The value represents a number less than System.Byte.MinValue or greater than System.Byte.MaxValue. |
ToChar(String)
Converts the first character of a specified string to a Unicode character.
Declaration
public static char ToChar(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string of length 1. |
Returns
| Type | Description |
|---|---|
| System.Char | Returns a Unicode character that is equivalent to the first and only character in value. |
Remarks
The framework does not know a culture specific convert method, so does this library.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.FormatException | The length of value is not 1. |
ToCultureInfo(String)
Creates a new System.Globalization.CultureInfo with the given name.
Declaration
public static CultureInfo ToCultureInfo(this string name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The name of the culture. |
Returns
| Type | Description |
|---|---|
| System.Globalization.CultureInfo | Returns the System.Globalization.CultureInfo with the given name. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | name can not be null. |
| System.Globalization.CultureNotFoundException | Culture is not supported. |
ToDateTime(String)
Converts the given string to a date time value.
Declaration
public static DateTime ToDateTime(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
Returns
| Type | Description |
|---|---|
| System.DateTime | Returns the date time value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.FormatException | Value does not contain a valid string representation of a date and time. |
ToDateTime(String, IFormatProvider)
Converts the given string to a date time value.
Declaration
public static DateTime ToDateTime(this string value, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
| System.IFormatProvider | formatProvider | The format provider. |
Returns
| Type | Description |
|---|---|
| System.DateTime | Returns the date time value. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentNullException | The format provider can not be null. |
| System.FormatException | Value does not contain a valid string representation of a date and time. |
ToDecimal(String)
Converts the given string to a decimal.
Declaration
public static decimal ToDecimal(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The decimal. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.FormatException | The value is not in the correct format. |
| System.OverflowException | value represents a number less than System.Decimal.MinValue or greater than System.Decimal.MaxValue. |
ToDecimal(String, IFormatProvider)
Converts the given string to a decimal.
Declaration
public static decimal ToDecimal(this string value, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
| System.IFormatProvider | formatProvider | The format provider. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The decimal. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentNullException | The format provider can not be null. |
| System.FormatException | The value is not in the correct format. |
| System.OverflowException | value represents a number less than System.Decimal.MinValue or greater than System.Decimal.MaxValue. |
ToDouble(String)
Converts the given string to a double.
Declaration
public static double ToDouble(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
Returns
| Type | Description |
|---|---|
| System.Double | The double. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.FormatException | value does not represent a number in a valid format. |
| System.OverflowException | value represents a number that is less than System.Double.MinValue or greater than System.Double.MaxValue. |
ToDouble(String, IFormatProvider)
Converts the given string to a double.
Declaration
public static double ToDouble(this string value, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
| System.IFormatProvider | formatProvider | The format provider. |
Returns
| Type | Description |
|---|---|
| System.Double | The double. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentNullException | The format provider can not be null. |
| System.FormatException | value does not represent a number in a valid format. |
| System.OverflowException | value represents a number that is less than System.Double.MinValue or greater than System.Double.MaxValue. |
ToEnum<T>(String, Boolean)
Converts a string to an enumeration.
Declaration
public static T ToEnum<T>(this string value, bool ignoreCase = true)where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The String value to convert. |
| System.Boolean | ignoreCase | Determines whether or not to ignore the casing of the string. |
Returns
| Type | Description |
|---|---|
| T | Returns the converted enumeration value. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the enumeration. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
ToGuid(String)
Converts the given string to a GUID.
Declaration
public static Guid ToGuid(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
Returns
| Type | Description |
|---|---|
| System.Guid | Returns the converted GUID. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.FormatException | value is not in a recognized format. |
ToInt16(String)
Converts the given string to a Int16.
Declaration
public static short ToInt16(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
Returns
| Type | Description |
|---|---|
| System.Int16 | Returns the converted Int16. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.FormatException | value s not in the correct format. |
| System.OverflowException | value represents a number less than System.Int16.MinValue or greater than System.Int16.MaxValue. |
ToInt16(String, IFormatProvider)
Converts the given string to a Int16.
Declaration
public static short ToInt16(this string value, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
| System.IFormatProvider | formatProvider | The format provider. |
Returns
| Type | Description |
|---|---|
| System.Int16 | Returns the converted Int16. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentNullException | The format provider can not be null. |
| System.FormatException | value s not in the correct format. |
| System.OverflowException | value represents a number less than System.Int16.MinValue or greater than System.Int16.MaxValue. |
ToInt32(String)
Converts the given string to a Int32.
Declaration
public static int ToInt32(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
Returns
| Type | Description |
|---|---|
| System.Int32 | Returns the converted Int32. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.FormatException | value s not in the correct format. |
| System.OverflowException | value represents a number less than System.Int32.MinValue or greater than System.Int32.MaxValue. |
ToInt32(String, IFormatProvider)
Converts the given string to a Int32.
Declaration
public static int ToInt32(this string value, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
| System.IFormatProvider | formatProvider | The format provider. |
Returns
| Type | Description |
|---|---|
| System.Int32 | Returns the converted Int32. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentNullException | The format provider can not be null. |
| System.FormatException | value s not in the correct format. |
| System.OverflowException | value represents a number less than System.Int32.MinValue or greater than System.Int32.MaxValue. |
ToInt64(String)
Converts the given string to a Int64.
Declaration
public static long ToInt64(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
Returns
| Type | Description |
|---|---|
| System.Int64 | Returns the converted Int64. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.FormatException | value s not in the correct format. |
| System.OverflowException | value represents a number less than System.Int64.MinValue or greater than System.Int64.MaxValue. |
ToInt64(String, IFormatProvider)
Converts the given string to a Int64.
Declaration
public static long ToInt64(this string value, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string to convert. |
| System.IFormatProvider | formatProvider | The format provider. |
Returns
| Type | Description |
|---|---|
| System.Int64 | Returns the converted Int64. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
| System.ArgumentNullException | The format provider can not be null. |
| System.FormatException | value s not in the correct format. |
| System.OverflowException | value represents a number less than System.Int64.MinValue or greater than System.Int64.MaxValue. |
Truncate(String, Int32, String)
Truncates the given string to the specified maximum length and adds the specified suffix to the end of the truncated string.
Declaration
public static string Truncate(this string str, int maxLength, string suffix = "...")
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string to truncate. |
| System.Int32 | maxLength | The maximum length of the truncated string. |
| System.String | suffix | The suffix of the truncated string. |
Returns
| Type | Description |
|---|---|
| System.String | The truncated string. |
TryParsBoolean(String, out Boolean)
Tries to convert the specified string representation of a logical value to its System.Boolean equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsBoolean(this string value, out bool outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing the value to convert. |
| System.Boolean | outValue | When this method returns, if the conversion succeeded, contains true if value is equal to System.Boolean.TrueString or false if value is equal to System.Boolean.FalseString. If the conversion failed, contains false. The conversion fails if value is null or is not equal to the value of either the System.Boolean.TrueString or System.Boolean.FalseString field. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
TryParsByte(String, out Byte)
Tries to convert the string representation of a number to its System.Byte equivalent, and returns a value that indicates whether the conversion succeeded.
Declaration
public static bool TryParsByte(this string value, out byte outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string that contains a number to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer numberStyle. The string to pars. |
| System.Byte | outValue | The parsed value. When this method returns, contains the System.Byte value equivalent to the number contained in s if the conversion succeeded, or zero if the conversion failed. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
TryParsByte(String, NumberStyles, IFormatProvider, out Byte)
Converts the string representation of a number in a specified numberStyle and culture-specific format to its System.Byte equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsByte(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, out byte outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. The string is interpreted using the numberStyle specified by numberStyle. |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of enumeration values that indicates the numberStyle elements that can be present in s. A typical value to specify is System.Globalization.NumberStyles.Integer. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about s. If formatProvider is null, the thread current culture is used. |
| System.Byte | outValue | When this method returns, contains the 8-bit unsigned integer value equivalent to the number contained in s if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or System.String.Empty, is not of the correct format, or represents a number less than System.Byte.MinValue or greater than System.Byte.MaxValue. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formatProvider can not be null. |
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-style is not a combination of System.Globalization.NumberStyles.AllowHexSpecifier and System.Globalization.NumberStyles.HexNumber values. |
TryParsChar(String, out Char)
Converts the value of the specified string to its equivalent Unicode character. A return code indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsChar(this string value, out char outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string that contains a single character. |
| System.Char | outValue | When this method returns, contains a Unicode character equivalent to the sole character in s, if the conversion succeeded, or an undefined value if the conversion failed. The conversion fails if the s parameter is null or the length of s is not 1. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
TryParsDateTime(String, out DateTime)
Converts the specified string representation of a date and time to its System.DateTime equivalent and returns a value that indicates whether the conversion succeeded.
Declaration
public static bool TryParsDateTime(this string value, out DateTime result)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A System.String containing a date and time to convert. |
| System.DateTime | result | When this method returns, contains the System.DateTime value equivalent to the date and time contained in value, if the conversion succeeded, or System.DateTime.MinValue if the conversion failed. The conversion fails if the value parameter is null, is an empty string (""), or does not contain a valid string representation of a date and time. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the s parameter was converted successfully; otherwise, false. |
TryParsDateTime(String, IFormatProvider, DateTimeStyles, out DateTime)
Converts the specified string representation of a date and time to its System.DateTime equivalent using the specified culture-specific format information and formatting style, and returns a value that indicates whether the conversion succeeded.
Declaration
public static bool TryParsDateTime(this string value, IFormatProvider formatProvider, DateTimeStyles dateTimeStyle, out DateTime result)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A System.Stringcontaining a date and time to convert. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about value. |
| System.Globalization.DateTimeStyles | dateTimeStyle | A bitwise combination of enumeration values that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is System.Globalization.DateTimeStyles.None. |
| System.DateTime | result | When this method returns, contains the System.DateTime value equivalent to the date and time contained in value, if the conversion succeeded, or System.DateTime.MinValue if the conversion failed. The conversion fails if the value parameter is null, is an empty string (""), or does not contain a valid string representation of a date and time. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the s parameter was converted successfully; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The format provider can not be null. |
| System.ArgumentException | dateTimeStyle is not a valid System.Globalization.DateTimeStyles value.-or-styles contains an invalid combination of System.Globalization.DateTimeStyles values (for example, both System.Globalization.DateTimeStyles.AssumeLocal and System.Globalization.DateTimeStyles.AssumeUniversal). |
TryParsDateTimeExact(String, String, IFormatProvider, DateTimeStyles, out DateTime)
Converts the specified string representation of a date and time to its DateTime equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded.
Declaration
public static bool TryParsDateTimeExact(this string value, string format, IFormatProvider formatProvider, DateTimeStyles dateTimeStyle, out DateTime outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A System.String containing a date and time to convert. |
| System.String | format | The required format of s. See the Remarks section for more information. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about value. |
| System.Globalization.DateTimeStyles | dateTimeStyle | A bitwise combination of one or more enumeration values that indicate the permitted format of value. |
| System.DateTime | outValue | When this method returns, contains the sSystem.DateTime value equivalent to the date and time contained in value, if the conversion succeeded, or System.DateTime.MinValue if the conversion failed. The conversion fails if either the s or format parameter is null, is an empty string, or does not contain a date and time that correspond to the pattern specified in format. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | format can not be null. |
| System.ArgumentNullException | format provider can not be null. |
| System.ArgumentException | dateTimeStyle is not a valid System.Globalization.DateTimeStyles value.-or-styles contains an invalid combination of System.Globalization.DateTimeStyles values (for example, both System.Globalization.DateTimeStyles.AssumeLocal and System.Globalization.DateTimeStyles.AssumeUniversal). |
TryParsDateTimeExact(String, String[], IFormatProvider, DateTimeStyles, out DateTime)
Converts the specified string representation of a date and time to its System.DateTime equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly. The method returns a value that indicates whether the conversion succeeded.
Declaration
public static bool TryParsDateTimeExact(this string value, string[] formats, IFormatProvider formatProvider, DateTimeStyles dateTimeStyle, out DateTime outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A System.String containing a date and time to convert. |
| System.String[] | formats | An array of allowable formats of s. See the Remarks section for more information. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about value. |
| System.Globalization.DateTimeStyles | dateTimeStyle | A bitwise combination of one or more enumeration values that indicate the permitted format of value. |
| System.DateTime | outValue | When this method returns, contains the sSystem.DateTime value equivalent to the date and time contained in value, if the conversion succeeded, or System.DateTime.MinValue if the conversion failed. The conversion fails if either the s or format parameter is null, is an empty string, or does not contain a date and time that correspond to the pattern specified in format. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
Remarks
The DateTime.TryParseExact(String, String[], IFormatProvider, DateTimeStyles, DateTime) method parses the string representation of a date that matches any one of the patterns assigned to the formats parameter. It is like the DateTime.ParseExact(String, String[], IFormatProvider, DateTimeStyles) method, except the TryParseExact method does not throw an exception if the conversion fails.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formats can not be null. |
| System.ArgumentNullException | format provider can not be null. |
| System.ArgumentException | dateTimeStyle is not a valid System.Globalization.DateTimeStyles value.-or-styles contains an invalid combination of System.Globalization.DateTimeStyles values (for example, both System.Globalization.DateTimeStyles.AssumeLocal and System.Globalization.DateTimeStyles.AssumeUniversal). |
TryParsDecimal(String, out Decimal)
Converts the string representation of a number to its System.Decimal equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsDecimal(this string value, out decimal outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string representation of the number to convert. |
| System.Decimal | outValue | The parsed value. When this method returns, contains the System.Decimal number that is equivalent to the numeric value contained in s, if the conversion succeeded, or is zero if the conversion failed. The conversion fails if the s parameter is null or System.String.Empty, is not a number in a valid format, or represents a number less than System.Decimal.MinValue or greater than System.Decimal.MaxValue. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
TryParsDecimal(String, NumberStyles, IFormatProvider, out Decimal)
Converts the string representation of a number to its System.Decimal equivalent using the specified numberStyle and culture-specific format. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsDecimal(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, out decimal outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The string representation of the number to convert. |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of enumeration values that indicates the permitted format of value. A typical value to specify is System.Globalization.NumberStyles.Number. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific parsing information about value. |
| System.Decimal | outValue | When this method returns, contains the System.Decimal number that is equivalent to the numeric value contained in s, if the conversion succeeded, or is zero if the conversion failed. The conversion fails if the s parameter is null or System.String.Empty, is not in a format compliant with numberStyle, or represents a number less than System.Decimal.MinValue or greater than System.Decimal.MaxValue. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formatProvider can not be null. |
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-style is the System.Globalization.NumberStyles.AllowHexSpecifier value. |
TryParsDouble(String, out Double)
Converts the string representation of a number to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsDouble(this string value, out double outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Double | outValue | When this method returns, contains the double-precision floating-point number equivalent of the value parameter, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the value parameter is null or System.String.Empty, is not a number in a valid format, or represents a number less than System.Double.MinValue or greater than System.Double.MaxValue. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
TryParsDouble(String, NumberStyles, IFormatProvider, out Double)
Converts the string representation of a number in a specified numberStyle and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsDouble(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, out double outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of System.Globalization.NumberStyles values that indicates the permitted format of value. A typical value to specify is System.Globalization.NumberStyles.Float combined with System.Globalization.NumberStyles.AllowThousands. |
| System.IFormatProvider | formatProvider | An System.IFormatProvider that supplies culture-specific formatting information about value. |
| System.Double | outValue | When this method returns, contains a double-precision floating-point number equivalent of the numeric value or symbol contained in value, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the value parameter is null or System.String.Empty, is not in a format compliant with numberStyle, represents a number less than System.SByte.MinValue or greater than System.SByte.MaxValue, or if numberStyle is not a valid combination of System.Globalization.NumberStyles enumerated constants. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-numberStyle includes the System.Globalization.NumberStyles.AllowHexSpecifier value. |
| System.ArgumentNullException | formatProvider can not be null. |
TryParsGuid(String, out Guid)
Converts the string representation of a GUID to the equivalent System.Guid structure.
Declaration
public static bool TryParsGuid(this string value, out Guid outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The GUID to convert. |
| System.Guid | outValue | The structure that will contain the parsed value. If the method returns true,result contains a valid System.Guid. If the method returns false, result equals System.Guid.Empty. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parse operation was successful; otherwise, false. |
TryParsInt16(String, NumberStyles, IFormatProvider, out Int16)
Converts the string representation of a number in a specified numberStyle and culture-specific format to its 16-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsInt16(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, out short outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of enumeration values that indicates the numberStyle elements that can be present in value. A typical value to specify is System.Globalization.NumberStyles.Integer. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about value. |
| System.Int16 | outValue | When this method returns, contains the 16-bit signed integer value equivalent to the number contained in s, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or System.String.Empty, is not in a format compliant with numberStyle, or represents a number less than System.Int16.MinValue or greater than System.Int16.MaxValue. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formatProvider can not be null. |
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-style is not a combination of System.Globalization.NumberStyles.AllowHexSpecifier and System.Globalization.NumberStyles.HexNumber values. |
TryParsInt16(String, out Int16)
Converts the string representation of a number to its 16-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsInt16(this string value, out short outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Int16 | outValue | When this method returns, contains the 16-bit signed integer value equivalent to the number contained in s, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or System.String.Empty, is not of the correct format, or represents a number less than System.Int16.MinValue or greater than System.Int16.MaxValue. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
TryParsInt32(String, NumberStyles, IFormatProvider, out Int32)
Converts the string representation of a number in a specified numberStyles and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsInt32(this string value, NumberStyles numberStyles, IFormatProvider formatProvider, out int outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. The string is interpreted using |
| System.Globalization.NumberStyles | numberStyles | A bitwise combination of enumeration values that indicates the numberStyles elements that can be present in value. A typical value to specify is System.Globalization.NumberStyles.Integer. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about value. |
| System.Int32 | outValue | When this method returns, contains the 32-bit signed integer value equivalent to the number contained in s, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or System.String.Empty, is not in a format compliant with numberStyles, or represents a number less than System.Int32.MinValue or greater than System.Int32.MaxValue. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formatProvider can not be null. |
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-style is not a combination of System.Globalization.NumberStyles.AllowHexSpecifier and System.Globalization.NumberStyles.HexNumber values. |
TryParsInt32(String, out Int32)
Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsInt32(this string value, out int outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Int32 | outValue | When this method returns, contains the 32-bit signed integer value equivalent to the number contained in s, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or System.String.Empty, is not of the correct format, or represents a number less than System.Int32.MinValue or greater than System.Int32.MaxValue. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |
TryParsInt64(String, NumberStyles, IFormatProvider, out Int64)
Converts the string representation of a number in a specified numberStyle and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsInt64(this string value, NumberStyles numberStyle, IFormatProvider formatProvider, out long outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. The string is interpreted using |
| System.Globalization.NumberStyles | numberStyle | A bitwise combination of enumeration values that indicates the numberStyle elements that can be present in value. A typical value to specify is System.Globalization.NumberStyles.Integer. |
| System.IFormatProvider | formatProvider | An object that supplies culture-specific formatting information about value. |
| System.Int64 | outValue | When this method returns, contains the 64-bit signed integer value equivalent to the number contained in s, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or System.String.Empty, is not in a format compliant with numberStyle, or represents a number less than System.Int64.MinValue or greater than System.Int64.MaxValue. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | formatProvider can not be null. |
| System.ArgumentException | numberStyle is not a System.Globalization.NumberStyles value. -or-style is not a combination of System.Globalization.NumberStyles.AllowHexSpecifier and System.Globalization.NumberStyles.HexNumber values. |
TryParsInt64(String, out Int64)
Converts the string representation of a number to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.
Declaration
public static bool TryParsInt64(this string value, out long outValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A string containing a number to convert. |
| System.Int64 | outValue | When this method returns, contains the 64-bit signed integer value equivalent to the number contained in s, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or System.String.Empty, is not of the correct format, or represents a number less than System.Int64.MinValue or greater than System.Int64.MaxValue. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the parsing was successful, otherwise false. |
TryToEnum<T>(String, out T, Boolean)
Tries to convert a string value to an enum.
Declaration
public static bool TryToEnum<T>(string value, out T outValue, bool ignoreCase = true)where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The String value to convert. |
| T | outValue | The output value. |
| System.Boolean | ignoreCase | Determines whether or not to ignore the casing of the string. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns the converted enum value. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the enum. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The value can not be null. |