IsString C# and VB.NET Extension method

Here is a quick and dirty regex based IsString() .Net extension method.

C# version

public static bool IsString(this object word)
           return word == null ? false : Regex.IsMatch(word.ToString(), @"^[A-Za-z]+\Z");

VB.Net version

 <System.Runtime.CompilerServices.Extension> _
   Public Function IsString(word As Object) As Boolean
       Return If(word Is Nothing, False, Regex.IsMatch(word.ToString(), "^[A-Za-z]+\Z"))
   End Function

The method will match strings only no spaces or other characters will be matched


Comments are closed