Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Handy Extension Methods

, 5 Jun 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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);
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

FDW

Netherlands Netherlands
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141216.1 | Last Updated 5 Jun 2011
Article Copyright 2011 by FDW
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid