Created
July 11, 2013 20:28
-
-
Save jeremykdev/5978945 to your computer and use it in GitHub Desktop.
Collection of extension methods for working with strings in .NET
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace net.datacowboy | |
{ | |
public static class StringExtensionMethods | |
{ | |
/// <summary> | |
/// Remove non-digit characters from a string | |
/// </summary> | |
public static string StripNonDigitCharacters(this string input) | |
{ | |
Regex re = new Regex(@"\D"); | |
return re.Replace(input, String.Empty); | |
} | |
/// <summary> | |
/// Test if string matches a regular expression pattern | |
/// </summary> | |
public static bool IsRegularExpressionMatch(this string input, string regularExpressionPattern) | |
{ | |
return input.IsRegularExpressionMatch(new Regex(regularExpressionPattern)); | |
} | |
/// <summary> | |
/// Test if string matches a regular expression | |
/// </summary> | |
public static bool IsRegularExpressionMatch(this string input, Regex regExp) | |
{ | |
return regExp.IsMatch(input); | |
} | |
/// <summary> | |
/// Test if string length within given range | |
/// </summary> | |
public static bool IsLengthWithinRange(this string input, int min, int max) | |
{ | |
return (input.Length >= min && input.Length <= max); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment