Last post Jan 24, 2007 05:06 AM by Zhao Ji Ma - MSFT
Jan 19, 2007 08:28 AM|priyank.kansal|LINK
I want to convert an Html or Hash code into Unicode.
e.g. الادارة = الادارة
where "الادارة" is a hash code and الادارة is it's unicode value.
Jan 22, 2007 08:38 AM|Zhao Ji Ma - MSFT|LINK
الادارة in not hash code, it is numeric character references of the original characters. it represents one character each, ا should be 1575 (decimal) in binary.
Have you tried HTMLDecode()?
Jan 22, 2007 11:12 AM|priyank.kansal|LINK
No, I never tried the code.
Can you please explain me?
you want to say that if i convert this integer number to string then it will generate the desired unicode?
Jan 23, 2007 12:14 AM|Zhao Ji Ma - MSFT|LINK
Here is one example that will make you better understand this, First of all, I assume we use the ASCII character set.
The ASCII value of "Asp" is.
Then the numerical character reference for "asp.net" is
Please note I put &#-1 at end of the tring in my code to mark the end of thring to simplify.
Here is my code demonstrate how to decode it (unfortuately, Server.Decode() provided in my last post doesn't work for this senario), so I decide to write a simple one to decode it.
protected void Page_Load(object sender, EventArgs e)
String EncodedString = "Asp.net&#-1";
byte bytes = new byte;
// hardcoded string character length;
int byteIndex = 0;
at = 0;
start = 0;
int last = -1;
while ((start < EncodedString.Length) && (at > -1))
at = EncodedString.IndexOf("&#", start); // find "&#" in string one by one
if (at == -1) break;
start = at + 2;
if (last != -1)
temp = Convert.ToByte(EncodedString.Substring(last, at - last));
// Convert string "65", "115" to a byte and assign to it bytes array
bytes[byteIndex++] = temp;
last = start;
Response.BinaryWrite(bytes); // Output bytes
(1) الادارة means a sequence of bytes with decimal value:
1575 1604 1575 1583 1575 1585 1577
however it doesn't say the original encoding of the bytes(Unicode or other Multiplebyte encoding). since these values are greater than (256), it looks like two-byte encoding.
(2) You can customize my code to output the byte. But please note my code assume it is single byte encoding.
(3) Please check what is the original encoding, if it is from html file, what is the character set this html uses. Please provide other details.
Hope it helps!
Jan 23, 2007 03:29 AM|priyank.kansal|LINK
I am very thankful to you. I got the solution from Server.HtmlDecode() function.
just pass your code as parameter and get the answer.
Jan 23, 2007 04:39 AM|Zhao Ji Ma - MSFT|LINK
I'm glad that you have solved this issue. However I was wondering why Server.HtmlDecode() doesn't work for me now, I thought it should work.
Jan 24, 2007 02:26 AM|priyank.kansal|LINK
I am not able to understand that why it is not working for you. Whereas it's working fine here.
Jan 24, 2007 05:06 AM|Zhao Ji Ma - MSFT|LINK
Never mind, I'll check this.