Re: I cannot reliably write the Hex number "83" to a stream

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"ajmastrean" <ajmastrean@xxxxxxxxx> wrote in message
news:6762e194-cd29-46b5-a222-c496782ba26f@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I cannot get any (hex) number in the "0x80"-"0x89" range (inclusive)
to write properly to a file. Any number in this range magically
transforms itself into "0x3F". For instance, debugging shows that
"0x83" = UInt16 "131" and that converts to Char (curly) "f". Any
information would be helpful.

String[] hexNum = { "79", "80", "89", "90" };
System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(@"C:
\test.dbf", true, System.Text.Encoding.Default);

The only thing the "default" encoding is good for is sending to another .NET
program that also uses the default encoding. You're giving it permission to
store the data in the file any way it chooses.

If you need a particular encoding, then set the encoding to what you need.

Or use byte instead of char, bytes do not undergo encoding transformations.


foreach (String hex in hexNum)
{
Char hexChar = (Char)UInt16.Parse(hex,
System.Globalization.NumberStyles.HexNumber);
streamWriter.Write(hexChar);
}

streamWriter.Flush();
streamWriter.Close();


.



Relevant Pages

  • Re: Creating ANSI text files with international characters
    ... I've got the vCalendar part right, except for the file encoding. ... What exactly do you mean by "ANSI" here? ... No. Create a FileStream, and then a StreamWriter on top of that, ... If you specify the correct encoding, ...
    (microsoft.public.dotnet.framework)
  • Re: Writing German characters to sequential file
    ... specify a German code page in the stream writer command? ... You must choose one that contains the Umlaut, for example codepage ... don't pass an Encoding object to the StreamWriter. ...
    (microsoft.public.dotnet.languages.vb)
  • I cannot reliably write the Hex number "83" to a stream
    ... transforms itself into "0x3F". ... For instance, debugging shows that ... System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(@"C: ... Char hexChar = UInt16.Parse(hex, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Writing German characters to sequential file
    ... specify a German code page in the stream writer command? ... You must choose one that contains the Umlaut, for example codepage ... don't pass an Encoding object to the StreamWriter. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Console ascii problem
    ... the StreamWriter class for the specified stream, ... encoding and the default buffer size. ... Exact approach depends on your thread culture, ... Replaces the format item in a specified String with the text ...
    (microsoft.public.dotnet.languages.vb)