473,417 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

Byte array to string without character conversion?

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

Nov 20 '05 #1
5 2262
"Kasper Hansen" <ka**********@h-hansen.dk> schrieb
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).
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
> 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
Nov 20 '05 #3
* "Kasper Hansen" <ka**********@h-hansen.dk> scripsit:
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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
> 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
Nov 20 '05 #5
"Kasper Hansen" <ka**********@h-hansen.dk> schrieb
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?


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.
--
Armin

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steve Mauldin | last post by:
I came across an example in the MSDN documentation using RC2 encryption(the link to the article is at the end of this message). When I tried it I had a problem with getting back the same length...
43
by: Bill Cunningham | last post by:
I've been reading the C standard online and I'm puzzled as to what multibyte chars are. Wide chars I believe would be characters for languages such as cantonese or Japanese. I know the ASCII...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
4
by: Dennis Myrén | last post by:
Hi. Is there a way to utilize the great primitive data type formatting routines available in .NET without working with strings? I want a byte directly rather than a string. I think it is...
3
by: pkumar | last post by:
How to convert this byte array to string byte b=new byte; Is there any function or I need read one by one and build the string thanks
4
by: Richard506 | last post by:
If you take this Byte Arra Dim bytes() As Byte = { 207, 224, 135, 161, 253, 233, 111, 110, 99, 111, 100, 105, 110, 103, 32, 69, 120, 97, 109, 112, 108, 101 and write the byte array to disk...
2
by: Jeff Stewart | last post by:
I wrote the following function to accomodate a legacy driver function that only accepted VB6-style strings. The driver expects a string that represents an array of binary data to be sent over USB....
4
by: ThunderMusic | last post by:
Hi, I have to go from Byte() to String, do some processing then reconvert the String to byte() but using ascii format, not unicode. I currently use a stream to write the char()...
11
by: chaitali.pats | last post by:
Hi , I have implemented MD5 in C language . I am getting an output of 32 bits Hexadecimal number . for example : 83a80d3ca057492f0ce99ac1db8dced0 I need to convert this string same to 16...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.