Using code pages

C

Claire

I'm writing strings to an embedded console that only supports Extended ASCII
Code Page 437.
The strings are stored in a lookup table in a database .

My original code is as follows which writes to a memory stream:

System.Text.ASCIIEncoding Encoding = new System.Text.ASCIIEncoding();
MachineIDs.Write(Encoding.GetBytes(EquipmentRecord.LabelID));
MachineIDs.Write('\0');
MachineIDs.Write(Encoding.GetBytes(EquipmentRecord.EnglishDesc));
MachineIDs.Write('\0');
MachineIDs.Write(Encoding.GetBytes(EquipmentRecord.GermanDesc));
MachineIDs.Write('\0');

The above code isn't writing using the correct code page.The german 'ü' char
0xFC is being written as char 0x3F using the above.

How do I specify a code page please?

thanks
Claire
 
M

Marc Gravell

Are you after 0x81?
Encoding enc = Encoding.GetEncoding(437);
char[] c = { (char)0xFC};
byte[] bytes = enc.GetBytes(c);

Marc
 
M

Marc Gravell

(for reference, I only used the char[] syntax to avoid the character
getting corrupted between your client and mine... strings should work
fine too)

Marc
 
J

Jon Skeet [C# MVP]

(for reference, I only used the char[] syntax to avoid the character
getting corrupted between your client and mine... strings should work
fine too)

One alternative:

string umlaut = "\u00fc";

Just to avoid the char[] stuff.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top