Hai friends,
There are many ways to detect if a String contains Special Characters. In this code snippet, I will show a quick way to detect special characters using Regex.

C# code for find  if a String contains Special Characters.

static void Main(string[] args)
{
    string str = "Th!s $tri^g c@n$ist $pecial ch@rs";
    Match match = Regex.Match(str, "[^a-z0-9]",
            RegexOptions.IgnoreCase);
    while (match.Success)
    {
        string key = match.Value;
        Console.Write(key);
        match = match.NextMatch();
    }
    Console.ReadLine();
}

0 comments

Related Posts Plugin for WordPress, Blogger...