How to find special characters using c# | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

How to find special characters using c#

Saturday

 Find if a String contains Special Characters using c#:

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.

Code: 

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:

Post a Comment

Share your thoughts here...

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets