Handy Extension Methods
Here is a couple for String and StringBuilder. The String versions are handy (compared to the already existing instance versions (that are actually being used)) because they work against null values (e.g., ((string)null).IsNullOrEmpty()).public static class ExtensionMethodsString{ ...
Here is a couple for String
and StringBuilder
. The String
versions are handy (compared to the already existing instance versions (that are actually being used)) because they work against null
values (e.g., ((string)null).IsNullOrEmpty()
).
public static class ExtensionMethodsString
{
public static bool IsNullOrWhiteSpace(this string psString)
{
return string.IsNullOrWhiteSpace(psString);
}
public static bool IsNullOrEmpty(this string psString)
{
return string.IsNullOrEmpty(psString);
}
}
public static class ExtensionMethodsStringBuilder
{
public static bool IsNullOrWhiteSpace(this StringBuilder poStringBuilder)
{
if (poStringBuilder.IsNullOrEmpty() == false)
for (int x = poStringBuilder.Length - 1; x >= 0; x--)
if (char.IsWhiteSpace(poStringBuilder[x]) == false)
return false;
return true;
}
public static bool IsNullOrEmpty(this StringBuilder poStringBuilder)
{
return (poStringBuilder == null) || (poStringBuilder.Length == 0);
}
}