Hello folks,
I have a problem to convert extended ascii to unicode. For example char 'œ' (decimal value 156) is in Ascii table but that is defferent in unicode table with value 339.
Therefore, in C#, Request.BinaryRead(byteCount); is reading 'œ' char with ascii value 156 but when it decode it with System.Convert.ToChar(btyValue[i]) function or other function, it is searching unicode table and there is no char with value 156 in unicode.
Is there any function that can do this convertion? that means, 'œ'has different ascii value (156) and unicode value (339), but i will encode and decode the char and get the same char.
Thanks in Advance.
Shuvra
Loading
Shuvra Dev SarkerPosted Jun 15, 2007, 12:14 PM
Thanks very much. It's works with your suggestion........ and latin1 (1252) is my codepage.
again thanks a lot.
Regards,
Shuvra
AlanPosted Jun 15, 2007, 9:15 AM
I've been thinking some more about this and, if you could identify a code page which contains the extended ASCII characters which are used in your file, then the problem would be solved.
For example, I found that code page 1252 (Latin 1) contained the character we were taking about earlier at position 156 and so this code worked fine:
string s = Encoding.GetEncoding(1252).GetString(new byte[]{156});
MessageBox.Show(s);
The problem is that there's lots of different versions of extended ASCII and lots of different code pages, so it's a matter of finding the right one. Here's the character table for code page 1252:
http://www.microsoft.com/globaldev/reference/sbcs/1252.mspx
Shuvra Dev SarkerPosted Jun 15, 2007, 6:54 AM
This problem is not for a particular char. I am uploading atleast 2MB .xls file in the server and server is storing that file in .txt and .xls format.....
problem is I am using Request.BinaryRead(byteCount); function to read all the data in server then process the data and store it in files..
this BinaryRead(), read the Ascii value but .net dont use ascii.. here is the main problem.. In ASP, there is not problem because it consider ascii.....
System.Text.Encoding.UTF8.GetString(btyValue)
System.Text.Encoding.UTF32.GetString(btyValue)
System.Text.Encoding.Unicode.GetString(btyValue) etc.
these functions can convert the whole byte array into string but they also make problem in extended ascii........ but I am surprised why .NET dont have this convertion function. There should be something???
If anyone knows, pls let me know. otherwise, I have to make a mapping function for whole extended Ascii chars.
Regards,
Shuvra
AlanPosted Jun 15, 2007, 6:24 AM
AFAIK, there are no methods in the .NET framework which can deal with this situation.
If it's just that particular character that's troublesome, I'd just do something like:
char c = (b == 156 ? (char)339 : (char)b);