It is impossible to produce an isomorphic HTML codec pair. Consider:
HtmlDecode("”””””") -> ”””””
how do you get back from ”””””
to the original string?
HtmlEncode
has to pick one encoding for ”
, and it goes for ”
as the shortest, most readable alternative. As long as you've got working Unicode, that's almost certainly the best choice.
If you don't, that's another argument... the advantage of ”
is that it's slightly more readable than ”
, but it only works in HTML (not XML) and you still have to fall back to character references for all the Unicode characters that don't have built-in entity names, so it's less consistent. For a character-reference encoder, create an XmlTextWriter
using the ASCII encoding and call writeString
on it.