I am interacting with a web server using a desktop client program in C# and .Net 3.5. I am using Fiddler to see what traffic the web browser sends, and emulate that. Sadly t
It seems horribly inefficient, but the only way I can think to do that is to look through each character:
public static string MyHtmlEncode(string value)
{
// call the normal HtmlEncode first
char[] chars = HttpUtility.HtmlEncode(value).ToCharArray();
StringBuilder encodedValue = new StringBuilder();
foreach(char c in chars)
{
if ((int)c > 127) // above normal ASCII
encodedValue.Append("&#" + (int)c + ";");
else
encodedValue.Append(c);
}
return encodedValue.ToString();
}