C
clintp
I have a byte array that contains 8-bit ascii characters. I'm not
particular about the codepage used to display them, but I have to
preserve the position in the string with something and be able to back
to the original byte implementation.
For example, this doesn't work:
// Bytes for .02{cent} in my standard codepage
byte [] ba = new Byte [] { 0x2e, 0x30, 0x32, 0x9b };
string s = System.Text.Encoding.ASCII.GetString(ba);
Console.WriteLine(s);
byte [] nb = Encoding.ASCII.GetBytes(s);
Console.WriteLine("{0:x} {1:x} {2:x} {3:x}",
nb[0], nb[1], nb[2], nb[3]);
What I get is:
..02{left arrow}
2e 30 32 1b
As expected, the 9b became 1b because the encoding was ASCII -- 7 bits.
[The cent sign became a left-arrow because of the codepage
differences. Fine. That's okay.]
What I want is:
..02{cent}
2e 30 32 9b
What I absolutely need to be able to do is convert the byte array into
a string, and then back to a byte array and then have it come back with
the same byte representation on the way out again.
Any help?
particular about the codepage used to display them, but I have to
preserve the position in the string with something and be able to back
to the original byte implementation.
For example, this doesn't work:
// Bytes for .02{cent} in my standard codepage
byte [] ba = new Byte [] { 0x2e, 0x30, 0x32, 0x9b };
string s = System.Text.Encoding.ASCII.GetString(ba);
Console.WriteLine(s);
byte [] nb = Encoding.ASCII.GetBytes(s);
Console.WriteLine("{0:x} {1:x} {2:x} {3:x}",
nb[0], nb[1], nb[2], nb[3]);
What I get is:
..02{left arrow}
2e 30 32 1b
As expected, the 9b became 1b because the encoding was ASCII -- 7 bits.
[The cent sign became a left-arrow because of the codepage
differences. Fine. That's okay.]
What I want is:
..02{cent}
2e 30 32 9b
What I absolutely need to be able to do is convert the byte array into
a string, and then back to a byte array and then have it come back with
the same byte representation on the way out again.
Any help?