Class StringUtilityExtensions
This is an extension implementation of the most common methods on the StringUtility class.
Inheritance
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class StringUtilityExtensions
Methods
| Improve this DocContainsAll(String, String[])
Returns a value indicating whether all of the specified values occurs within the source.
Declaration
public static bool ContainsAll(this string source, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.String[] | values | The System.String sequence to search within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This method performs an ordinal (case-insensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.
ContainsAll(String, StringComparison, String[])
Returns a value indicating whether all of the specified values occurs within the source.
Declaration
public static bool ContainsAll(this string source, StringComparison comparison, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
| System.String[] | values | The System.String sequence to search within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
ContainsAny(String, Char)
Returns a value indicating whether the specified value occurs within the source.
Declaration
public static bool ContainsAny(this string source, char value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.Char | value | The System.Char to search within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This method performs an ordinal (case-insensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.
ContainsAny(String, Char, StringComparison)
Returns a value indicating whether the specified value occurs within the source.
Declaration
public static bool ContainsAny(this string source, char value, StringComparison comparison)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.Char | value | The System.Char to search within |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
ContainsAny(String, Char[])
Returns a value indicating whether the specified values occurs within the source object.
Declaration
public static bool ContainsAny(this string source, params char[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.Char[] | values | The System.Char sequence to search within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This method performs an ordinal (case-sensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.
ContainsAny(String, String)
Returns a value indicating whether the specified value occurs within the source.
Declaration
public static bool ContainsAny(this string source, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.String | value | The System.String to search within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This method performs an ordinal (case-insensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.
ContainsAny(String, String, StringComparison)
Returns a value indicating whether the specified value occurs within the source.
Declaration
public static bool ContainsAny(this string source, string value, StringComparison comparison)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.String | value | The System.String to search within |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
ContainsAny(String, String[])
Returns a value indicating whether any of the specified values occurs within the source.
Declaration
public static bool ContainsAny(this string source, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.String[] | values | The System.String sequence to search within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This method performs an ordinal (case-insensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.
ContainsAny(String, StringComparison, Char[])
Returns a value indicating whether the specified values occurs within the source object.
Declaration
public static bool ContainsAny(this string source, StringComparison comparison, params char[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
| System.Char[] | values | The System.Char sequence to search within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
ContainsAny(String, StringComparison, String[])
Returns a value indicating whether any of the specified values occurs within the source.
Declaration
public static bool ContainsAny(this string source, StringComparison comparison, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
| System.String[] | values | The System.String sequence to search within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Count(String, Char)
Counts the occurrences of character in the specified source.
Declaration
public static int Count(this string source, char character)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The source to count occurrences of |
| System.Char | character | The System.Char value to count in |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of times the |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
EqualsAny(String, String[])
Returns a value indicating the specified source equals one of the specified values.
Declaration
public static bool EqualsAny(this string source, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.String[] | values | The System.String sequence to search within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This method performs an ordinal (case-sensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
EqualsAny(String, StringComparison, String[])
Returns a value indicating the specified source equals one of the specified values.
Declaration
public static bool EqualsAny(this string source, StringComparison comparison, params string[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The System.String to seek. |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
| System.String[] | values | The System.String sequence to search within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
Escape(String)
Escapes the given System.String the same way as the well known JavaScrip escape() function.
Declaration
public static string Escape(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The System.String to escape. |
Returns
| Type | Description |
|---|---|
| System.String | The input |
GetHashCode32(String)
Computes a suitable hash code from the specified System.String value.
Declaration
public static int GetHashCode32(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A System.String value. |
Returns
| Type | Description |
|---|---|
| System.Int32 | A 32-bit signed integer that is the hash code of |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
IsBase64(String)
Determines whether the specified value matches a Base64 structure.
Declaration
public static bool IsBase64(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The value to test for a Base64 structure. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This method will skip common Base64 structures typically used as checksums. This includes 32, 128, 160, 256, 384 and 512 bit checksums.
IsBase64(String, Func<String, Boolean>)
Determines whether the specified value matches a Base64 structure.
Declaration
public static bool IsBase64(this string value, Func<string, bool> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The value to test for a Base64 structure. |
| System.Func<System.String, System.Boolean> | predicate | A function delegate that provides custom rules for bypassing the Base64 structure check. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
IsCountableSequence(String)
Determines whether the specified value is a sequence of countable characters (hence, characters being either incremented or decremented with the same cardinality through out the sequence).
Declaration
public static bool IsCountableSequence(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The value to test for a sequence of countable characters. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
IsNullOrEmpty(IEnumerable<String>)
Determines whether a string sequence has at least one value that equals to null or empty.
Declaration
public static bool IsNullOrEmpty(this IEnumerable<string> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.String> | values | A string sequence in which to test for the presence of null or empty. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
IsSequenceOf<T>(IEnumerable<String>)
Determines whether the elements of the specified source is equivalent to the specified T.
Declaration
public static bool IsSequenceOf<T>(this IEnumerable<string> source)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.String> | source | A sequence in which to evaluate if a string value is equivalent to the specified |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of the expected values contained within the sequence of |
IsSequenceOf<T>(IEnumerable<String>, Func<String, CultureInfo, Boolean>)
Determines whether the elements of the specified source is equivalent to the specified T.
Declaration
public static bool IsSequenceOf<T>(this IEnumerable<string> source, Func<string, CultureInfo, bool> parser)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.String> | source | A sequence in which to evaluate if a string value is equivalent to the specified |
| System.Func<System.String, System.Globalization.CultureInfo, System.Boolean> | parser | The function delegate that evaluates if the elements of |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of the expected values contained within the sequence of |
IsSequenceOf<T>(IEnumerable<String>, CultureInfo)
Determines whether the elements of the specified source is equivalent to the specified T.
Declaration
public static bool IsSequenceOf<T>(this IEnumerable<string> source, CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.String> | source | A sequence in which to evaluate if a string value is equivalent to the specified |
| System.Globalization.CultureInfo | culture | The culture-specific formatting information to apply on the elements within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of the expected values contained within the sequence of |
IsSequenceOf<T>(IEnumerable<String>, CultureInfo, ITypeDescriptorContext)
Determines whether the elements of the specified source is equivalent to the specified T.
Declaration
public static bool IsSequenceOf<T>(this IEnumerable<string> source, CultureInfo culture, ITypeDescriptorContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.String> | source | A sequence in which to evaluate if a string value is equivalent to the specified |
| System.Globalization.CultureInfo | culture | The culture-specific formatting information to apply on the elements within |
| System.ComponentModel.ITypeDescriptorContext | context | The type-specific formatting information to apply on the elements within |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of the expected values contained within the sequence of |
IsSequenceOf<T>(IEnumerable<String>, CultureInfo, Func<String, CultureInfo, Boolean>)
Determines whether the elements of the specified source is equivalent to the specified T.
Declaration
public static bool IsSequenceOf<T>(this IEnumerable<string> source, CultureInfo culture, Func<string, CultureInfo, bool> parser)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.String> | source | A sequence in which to evaluate if a string value is equivalent to the specified |
| System.Globalization.CultureInfo | culture | The culture-specific formatting information to apply on the elements within |
| System.Func<System.String, System.Globalization.CultureInfo, System.Boolean> | parser | The function delegate that evaluates if the elements of |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of the expected values contained within the sequence of |
ParseFormat(String, Int32, out Int32)
Parses the given string for any format arguments (eg. Text{0}-{1}.).
Declaration
public static bool ParseFormat(this string format, int maxArguments, out int foundArguments)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | format | The desired string format to parse. |
| System.Int32 | maxArguments | The maximum allowed arguments in the string format. |
| System.Int32 | foundArguments | The number of arguments found in the string format. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
ParseFormat(String, out Int32)
Parses the given string for any format arguments (eg. Text{0}-{1}.).
Declaration
public static bool ParseFormat(this string format, out int foundArguments)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | format | The desired string format to parse. |
| System.Int32 | foundArguments | The number of arguments found in the string format. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
RemoveAll(String, Char[])
Returns a new string in which all the specified filter values has been deleted from the specified source.
Declaration
public static string RemoveAll(this string source, params char[] filter)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The source to delete occurrences found in |
| System.Char[] | filter | The filter containing the characters and/or words to delete. |
Returns
| Type | Description |
|---|---|
| System.String | A new string that is equivalent to |
RemoveAll(String, String[])
Returns a new string in which all the specified filter values has been deleted from the specified source.
Declaration
public static string RemoveAll(this string source, params string[] filter)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The source to delete occurrences found in |
| System.String[] | filter | The filter containing the characters and/or words to delete. |
Returns
| Type | Description |
|---|---|
| System.String | A new string that is equivalent to |
Remarks
This method performs an ordinal (case-sensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
RemoveAll(String, StringComparison, String[])
Returns a new string in which all the specified filter values has been deleted from the specified source.
Declaration
public static string RemoveAll(this string source, StringComparison comparison, params string[] filter)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | The source to delete occurrences found in |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
| System.String[] | filter | The filter containing the characters and/or words to delete. |
Returns
| Type | Description |
|---|---|
| System.String | A new string that is equivalent to |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
RemoveAll(String[], String[])
Returns a new string array in which all the specified filter values has been deleted from the specified source array.
Declaration
public static string[] RemoveAll(this string[] source, params string[] filter)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String[] | source | The source array to delete occurrences found in |
| System.String[] | filter | The filter containing the characters and/or words to delete. |
Returns
| Type | Description |
|---|---|
| System.String[] | A new string array that is equivalent to |
Remarks
This method performs an ordinal (case-sensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
RemoveAll(String[], StringComparison, String[])
Returns a new string array in which all the specified filter values has been deleted from the specified source array.
Declaration
public static string[] RemoveAll(this string[] source, StringComparison comparison, params string[] filter)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String[] | source | The source array to delete occurrences found in |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
| System.String[] | filter | The filter containing the characters and/or words to delete. |
Returns
| Type | Description |
|---|---|
| System.String[] | A new string array that is equivalent to |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
ReplaceAll(String, IEnumerable<StringReplacePair>, StringComparison)
Declaration
public static string ReplaceAll(this string value, IEnumerable<StringReplacePair> replacePairs, StringComparison comparison)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The System.String value to perform the replacement on. |
| System.Collections.Generic.IEnumerable<StringReplacePair> | replacePairs | A sequence of StringReplacePair values. |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
Returns
| Type | Description |
|---|---|
| System.String | A System.String equivalent to |
ReplaceAll(String, String, String)
Replaces all occurrences of oldValue in value, with newValue.
Declaration
public static string ReplaceAll(this string value, string oldValue, string newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The System.String value to perform the replacement on. |
| System.String | oldValue | The System.String value to be replaced. |
| System.String | newValue | The System.String value to replace all occurrences of |
Returns
| Type | Description |
|---|---|
| System.String | A System.String equivalent to |
Remarks
This method performs an System.StringComparison.OrdinalIgnoreCase search to find oldValue.
ReplaceAll(String, String, String, StringComparison)
Replaces all occurrences of oldValue in value, with newValue.
Declaration
public static string ReplaceAll(this string value, string oldValue, string newValue, StringComparison comparison)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The System.String value to perform the replacement on. |
| System.String | oldValue | The System.String value to be replaced. |
| System.String | newValue | The System.String value to replace all occurrences of |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
Returns
| Type | Description |
|---|---|
| System.String | A System.String equivalent to |
Shuffle(IEnumerable<String>)
Shuffles the specified values like a deck of cards.
Declaration
public static string Shuffle(this IEnumerable<string> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.String> | values | The values to be shuffled in the randomization process. |
Returns
| Type | Description |
|---|---|
| System.String | A random string from the shuffled |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
| System.ArgumentOutOfRangeException |
|
Split(String)
Returns a string array that contains the substrings of value that are delimited by a comma (",").
Declaration
public static string[] Split(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The value containing substrings and delimiters. |
Returns
| Type | Description |
|---|---|
| System.String[] | An array whose elements contain the substrings of |
Remarks
The following table shows the default values for the overloads of this method.
| Parameter | Default Value |
|---|---|
| delimiter | , |
| textQualifier | " |
| provider | System.Globalization.CultureInfo.InvariantCulture |
Split(String, String)
Returns a string array that contains the substrings of value that are delimited by delimiter.
Declaration
public static string[] Split(this string value, string delimiter)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The value containing substrings and delimiters. |
| System.String | delimiter | The delimiter specification. |
Returns
| Type | Description |
|---|---|
| System.String[] | An array whose elements contain the substrings of |
Split(String, String, String)
Returns a string array that contains the substrings of value that are delimited by delimiter. A parameter specifies the textQualifier that surrounds a field.
Declaration
public static string[] Split(this string value, string delimiter, string textQualifier)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The value containing substrings and delimiters. |
| System.String | delimiter | The delimiter specification. |
| System.String | textQualifier | The text qualifier specification that surrounds a field. |
Returns
| Type | Description |
|---|---|
| System.String[] | An array whose elements contain the substrings of |
StartsWith(String, IEnumerable<String>)
Determines whether the beginning of an instance of System.String matches at least one string in the specified sequence of strings.
Declaration
public static bool StartsWith(this string value, IEnumerable<string> startWithValues)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The System.String to compare. |
| System.Collections.Generic.IEnumerable<System.String> | startWithValues | A sequence of System.String values to match against. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This match is performed by using a default value of System.StringComparison.OrdinalIgnoreCase.
StartsWith(String, String[])
Determines whether the beginning of an instance of System.String matches at least one string in the specified sequence of strings.
Declaration
public static bool StartsWith(this string value, params string[] startWithValues)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The System.String to compare. |
| System.String[] | startWithValues | A sequence of System.String values to match against. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This match is performed by using a default value of System.StringComparison.OrdinalIgnoreCase.
StartsWith(String, StringComparison, IEnumerable<String>)
Determines whether the beginning of an instance of System.String matches at least one string in the specified sequence of strings.
Declaration
public static bool StartsWith(this string value, StringComparison comparison, IEnumerable<string> startWithValues)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The System.String to compare. |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
| System.Collections.Generic.IEnumerable<System.String> | startWithValues | A sequence of System.String values to match against. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
StartsWith(String, StringComparison, String[])
Determines whether the beginning of an instance of System.String matches at least one string in the specified sequence of strings.
Declaration
public static bool StartsWith(this string value, StringComparison comparison, params string[] startWithValues)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The System.String to compare. |
| System.StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
| System.String[] | startWithValues | A sequence of System.String values to match against. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This match is performed by using a default value of System.StringComparison.OrdinalIgnoreCase.
TrimAll(String)
Removes all occurrences of white-space characters from the specified value.
Declaration
public static string TrimAll(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A System.String value. |
Returns
| Type | Description |
|---|---|
| System.String | The string that remains after all occurrences of white-space characters are removed from the specified |
TrimAll(String, Char[])
Removes all occurrences of a set of characters specified in trimChars from the specified value.
Declaration
public static string TrimAll(this string value, params char[] trimChars)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | A System.String value. |
| System.Char[] | trimChars | An array of Unicode characters to remove. |
Returns
| Type | Description |
|---|---|
| System.String | The string that remains after all occurrences of the characters in the |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
Unescape(String)
Unescapes the given System.String the same way as the well known Javascript unescape() function.
Declaration
public static string Unescape(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The System.String to unescape. |
Returns
| Type | Description |
|---|---|
| System.String | The input |