Last active
August 29, 2015 14:04
-
-
Save pinalbhatt/19bfad106d5b8e17a595 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
C# Some Handy String Extension Methods | |
Code Snippet By: Pinal Bhatt [www.PBDesk.com] | |
*/ | |
using System; | |
public static class StringExtensions | |
{ | |
/// <summary> | |
/// Indicates whether invoking string object is null or an empty string. | |
/// </summary> | |
/// <param name="inputstr"></param> | |
/// <returns></returns> | |
public static bool IsNullOrEmpty(this string inputstr) | |
{ | |
return string.IsNullOrEmpty(inputstr); | |
} | |
/// <summary> | |
/// Returns true if invoking string matches with regex pattern | |
/// </summary> | |
/// <param name="original"></param> | |
/// <param name="regex"></param> | |
/// <returns></returns> | |
public static bool IsRegexMatch(this string original, string regex) | |
{ | |
return Regex.IsMatch(original, regex); | |
} | |
/// <summary> | |
/// Indicates whether invoking string object is not null and not an empty string. | |
/// </summary> | |
/// <param name="inputString"></param> | |
/// <returns></returns> | |
public static bool IsNotNullAndNotEmpty(this string inputString) | |
{ | |
return !string.IsNullOrEmpty(inputString); | |
} | |
/// <summary> | |
/// Returns an empty string if input string is null. | |
/// </summary> | |
/// <param name="inputString"></param> | |
/// <returns></returns> | |
public static string IfNullThenEmpty(this string inputstr) | |
{ | |
return inputString ?? string.Empty; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment