Byte array to string without character conversion?

  • Thread starter Thread starter Kasper Hansen
  • Start date Start date
K

Kasper Hansen

I need to search through a binary file to find a specific string and then
replace it with another string. However the
System.Text.Encoding.ASCII.GetString method i originally used seems to do
some character conversion. I also tried using UTF7-8 and Unicode
conversions, but the output is still converted. How do i get past this?

Thanks in advance,

Kasper Hansen
 
Kasper Hansen said:
I need to search through a binary file to find a specific string and
then replace it with another string. However the
System.Text.Encoding.ASCII.GetString method i originally used seems
to do some character conversion.

ASCII = 7bit = characters 0 - 127 only
I also tried using UTF7-8 and
Unicode conversions, but the output is still converted. How do i get
past this?

Which character encoding has been used to write into the file? You'd have to
know this first. If 1 character = 1 byte it's probably ANSI encoding
(System.Text.Encoding.Default).
 
Which character encoding has been used to write into the file? You'd have
to
know this first. If 1 character = 1 byte it's probably ANSI encoding
(System.Text.Encoding.Default).

Well, i just want the output to be exactly the same as the input. 0xFF =
0xFF and 0x7F = 0x7F and so on. I also tried the default encoding, but it
didn't work either. Any other suggestions?

/Kasper Hansen
 
* "Kasper Hansen said:
I need to search through a binary file to find a specific string and then
replace it with another string. However the
System.Text.Encoding.ASCII.GetString method i originally used seems to do
some character conversion. I also tried using UTF7-8 and Unicode
conversions, but the output is still converted. How do i get past this?

You may want to use 'Encoding.Default' to read the file with the
currently used codepage.
 
You may want to use 'Encoding.Default' to read the file with the
currently used codepage.

Sorry - you're both right. I overlooked a spot where i did the conversion
once more.
Thanks alot.

/Kasper Hansen
 
Kasper Hansen said:
Well, i just want the output to be exactly the same as the input.
0xFF = 0xFF and 0x7F = 0x7F and so on. I also tried the default
encoding, but it didn't work either. Any other suggestions?

Could you please show an example how you read/convert/display chars?
If you want to convert to Char/String, you must know the source
encoding because the byte value(s) must be converted to Unicode as
Chars are always Unicode encoded.
 
Back
Top