Class StringExtensionMethods
Extension methods for string.
Inheritance
StringExtensionMethods
Assembly: Benday.Common.dll
Syntax
public static class StringExtensionMethods
Methods
|
Edit this page
View Source
EqualsCaseInsensitive(string?, string?)
This method compares two strings for equality, ignoring case. If both strings are null, they are considered equal.
Declaration
public static bool EqualsCaseInsensitive(this string? value1, string? value2)
Parameters
Returns
|
Edit this page
View Source
IsNullOrWhitespace(string?)
This method checks if the string is null or empty. If the string is null or empty, it returns true.
Declaration
public static bool IsNullOrWhitespace(this string? value)
Parameters
Type |
Name |
Description |
string |
value |
|
Returns
|
Edit this page
View Source
SafeContains(string?, string)
This method checks if the string contains a value. If the string is null or empty, it returns false.
Declaration
public static bool SafeContains(this string? value, string containsValue)
Parameters
Returns
|
Edit this page
View Source
SafeContainsCaseInsensitive(string?, string)
This method checks if the string contains a value ignoring case. If the string is null or empty, it returns false.
Declaration
public static bool SafeContainsCaseInsensitive(this string? value, string containsValue)
Parameters
Returns
|
Edit this page
View Source
SafeToInt32(string?, int)
This method converts a string to an integer. If the string is null or empty, it returns the default value.
If the string cannot be converted to an integer, it returns the default value.
Declaration
public static int SafeToInt32(this string? value, int defaultValue = 0)
Parameters
Type |
Name |
Description |
string |
value |
|
int |
defaultValue |
|
Returns
|
Edit this page
View Source
SafeToString(string?, string)
This wraps the ToString() method and handles the case where the string is null. Returns the input string if it is not null, otherwise returns the default value.
Declaration
public static string SafeToString(this string? input, string defaultValue = "")
Parameters
Type |
Name |
Description |
string |
input |
|
string |
defaultValue |
Value to return if null. The default value is empty string.
|
Returns
|
Edit this page
View Source
ToStringThrowIfNullOrEmpty(string?, string)
This method converts a string to a string and throws an exception if the string is null or empty.
Declaration
public static string ToStringThrowIfNullOrEmpty(this string? input, string label = "")
Parameters
Type |
Name |
Description |
string |
input |
Input string to check
|
string |
label |
Optional label/name for the string to include in the exception
|
Returns
Exceptions