web 2.0

Email Obfuscator Extension Method

Hi,

I Quick Code Snippet in order to Obfuscate Email Addresses to prevent Web Crawlers from leech them ...

Code

public static String Obfuscate(this String s)
{
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s.Length; i++)
    {
        sb.AppendFormat("&#{0};", (Int32)s[i]);
    }
    return sb.ToString();
}

Usage Sample :

static void Main(string[] args)
{
    String email = "me@me.com";

    Console.WriteLine(email.Obfuscate());
}

Output :

&#109;&#101;&#64;&#109;&#101;&#46;&#99;&#111;&#109;

Hope this help’s!



Views(776)

kick it on DotNetKicks.com

Share/Save/Bookmark Subscribe

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

C#

Comments

Add comment


 

biuquote
Loading



Technorati Profile