How to Convert Unicode Character to HTML string?
Use function provided below to get HTML code for a Unicode String.
Its quite usefull when you want to write characters outside ASCII
limit.
Its quite usefull when you want to write characters outside ASCII
limit.
//language c#
public static string GetUnicode(string unicodeText)
{
int unicodeVal = 0;
string encoded = "";
foreach( char c in unicodeText)
{
unicodeVal = Convert.ToInt32(c);
//Debug.WriteLine(c.ToString & " : " & unicodeVal.ToString)
if((unicodeVal >= 49) && (unicodeVal <= 122))
{
//in 'ascii' range x30 to x7a which is 0-9A-Za-z plus some punctuation
encoded += c; // leave as-is
}
else
{
// outside 'ascii' range - encode
encoded += String.Concat("",
unicodeVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo),
";");
}
}
return encoded;
}


2 Comments:
It's not work on
XMLElement.SetAttribute("Attr", GetUnicode(str));
where value of str in russian language...Because in xml : Attr="О", but not Attr="О"...
How simple replace "&" by "&" in xml document ?
Thanks a lot. This really helped me out.
Post a Comment
Subscribe to Post Comments [Atom]
<< Home