Click here to Skip to main content
12,457,938 members (55,219 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

1.6K views
Posted

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

You may also be interested in...

Pro
Pro

Comments and Discussions

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