Class StringsExtensions
Provides extension methods for string operations, enhancing the built-in string manipulation capabilities.
Namespace: Coree.NETStandard.Extensions
Assembly: Coree.NETStandard.dll
Syntax
public static class StringsExtensions
Methods
| Edit this page View SourceIsValidJson(string)
Validates whether the specified string is valid JSON.
Declaration
public static bool IsValidJson(this string jsonString)
Parameters
Type | Name | Description |
---|---|---|
string | jsonString | The JSON string to validate. |
Returns
Type | Description |
---|---|
bool | true if the string is valid JSON; otherwise, false. |
IsValidXml(string)
Validates whether the specified string is well-formed XML.
Declaration
public static bool IsValidXml(this string xmlString)
Parameters
Type | Name | Description |
---|---|---|
string | xmlString | The XML string to validate. |
Returns
Type | Description |
---|---|
bool | true if the string is a well-formed XML; otherwise, false. |
SplitWith(string?, char[], StringSplitOptions, bool)
Splits the input string by an array of characters, treating them as individual delimiters, with options to control the split operation. Offers the option to remove the delimiters from the resulting array.
Declaration
public static string[] SplitWith(this string? input, char[] delimiter, StringSplitOptions options = StringSplitOptions.None, bool removeDelimiters = true)
Parameters
Type | Name | Description |
---|---|---|
string | input | The string to be split. |
char[] | delimiter | The array of characters joined to a string to use as delimiter |
StringSplitOptions | options | Specifies whether to omit empty or whitespace-only substrings from the resulting array. |
bool | removeDelimiters | When set to true, the delimiters themselves are excluded from the result array. |
Returns
Type | Description |
---|---|
string[] | An array of substrings that are delimited by the specified characters, optionally excluding the delimiters themselves. |
Remarks
This method constructs a string from the character array and uses regular expressions for splitting, which may have performance implications for large strings or a large number of delimiters. When removeDelimiters is true, it filters out any substring that matches one of the delimiters exactly, after splitting.
SplitWith(string?, string, StringSplitOptions, bool)
Splits the input string by a specified string delimiter, with options to control the split operation. Offers the option to remove the delimiter from the resulting array.
Declaration
public static string[] SplitWith(this string? input, string delimiter, StringSplitOptions options = StringSplitOptions.None, bool removeDelimiters = true)
Parameters
Type | Name | Description |
---|---|---|
string | input | The string to be split. |
string | delimiter | The string delimiter to split by. |
StringSplitOptions | options | Specifies whether to omit empty or whitespace-only substrings from the resulting array. |
bool | removeDelimiters | When set to true, the delimiter itself is excluded from the result array. |
Returns
Type | Description |
---|---|
string[] | An array of substrings that are delimited by the specified string, optionally excluding the delimiter itself. |
Remarks
This method uses regular expressions to split the input string, which may have performance implications for large strings or a large number of delimiters. When removeDelimiters is true, it filters out the delimiter if it matches exactly, after splitting.
SplitWith(string?, string[], StringSplitOptions, bool)
Splits the input string by multiple string delimiters, with options to control the split operation. Offers the option to remove the delimiters from the resulting array.
Declaration
public static string[] SplitWith(this string? input, string[] delimiters, StringSplitOptions options = StringSplitOptions.None, bool removeDelimiters = true)
Parameters
Type | Name | Description |
---|---|---|
string | input | The string to be split. |
string[] | delimiters | The array of string delimiters to split by. |
StringSplitOptions | options | Specifies whether to omit empty or whitespace-only substrings from the resulting array. |
bool | removeDelimiters | When set to false, the delimiters themselves are not excluded from the result array. |
Returns
Type | Description |
---|---|
string[] | An array of substrings that are delimited by any of the specified strings, optionally excluding the delimiters themselves. |
Remarks
This method uses regular expressions to split the input string, which may have performance implications for large strings or a large number of delimiters. When removeDelimiters is true, it filters out any substring that matches one of the delimiters exactly, after splitting.