This is my unicode String >
Désastres
The above String need to be converted to HTML Entity (Hex) as
Désastres
Below is the code, it converts the string to html entiry but in Decimal.
Can anyone help me to get the desired result?
static string EscapeAccentsToHtmlEntities(string source)
{
int length = source.Length;
var escaped = new StringBuilder();
for (int i = 0; i < length; i++)
{
char ch = source[i];
if ((ch >= '\x00a0') && (ch < 'Ā')) //U+{0:X4}
{
escaped.AppendFormat("&#{0};", ((int)ch).ToString(NumberFormatInfo.InvariantInfo)); //"&#{0};"
}
else
{
escaped.Append(ch);
}
}
return escaped.ToString();
}
Explaination: possible duplicates of this is for javascript / jquery