Using code pages

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Claire

    #1

    Using code pages

    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.ASC IIEncoding Encoding = new System.Text.ASC IIEncoding();
    MachineIDs.Writ e(Encoding.GetB ytes(EquipmentR ecord.LabelID)) ;
    MachineIDs.Writ e('\0');
    MachineIDs.Writ e(Encoding.GetB ytes(EquipmentR ecord.EnglishDe sc));
    MachineIDs.Writ e('\0');
    MachineIDs.Writ e(Encoding.GetB ytes(EquipmentR ecord.GermanDes c));
    MachineIDs.Writ e('\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


  • Marc Gravell

    #2
    Re: Using code pages

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

    Marc


    Comment

    • Marc Gravell

      #3
      Re: Using code pages

      (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


      Comment

      • Claire

        #4
        Re: Using code pages

        thanks marc :-)

        "Marc Gravell" <marc.gravell@g mail.comwrote in message
        news:eCOi8RWFIH A.5228@TK2MSFTN GP05.phx.gbl...


        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: Using code pages

          On Oct 23, 12:06 pm, "Marc Gravell" <marc.grav...@g mail.comwrote:
          (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

          Comment

          • Marc Gravell

            #6
            Re: Using code pages

            you are most welcome


            Comment

            • Marc Gravell

              #7
              Re: Using code pages

              good spot ;-p


              Comment

              Working...