Skip to main content

How to convert special characters to HTML encoded equivalents using C#.NET

public string HTMLEncodeSpecialChars(string text)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (char c in text){
if(c>127) // special chars
sb.Append(String.Format("&#{0};",(int)c));
else
sb.Append(c);
}
return sb.ToString();
}

Comments

  1. Hey I know this is off topic but I was wondering if you knew of any widgets I could add
    to my blog that automatically tweet my newest twitter updates.
    I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

    Take a look at my webpage: luxe vakantiehuizen ()

    ReplyDelete
  2. I used to be recommended this web site by means of my cousin.
    I am not sure whether or not this post is written by way of him
    as nobody else realize such distinct approximately my difficulty.
    You are incredible! Thank you!

    my web site ... vakantiehuisjes frankrijk []

    ReplyDelete
  3. You could certainly see your expertise within the article you write.
    The world hopes for even more passionate writers such as you who are
    not afraid to mention how they believe. Always go after your heart.


    Here is my blog post :: vakantiehuisjes - -

    ReplyDelete

Post a Comment