473,779 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Enc oding.ASCII.Get String 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 2283
"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.Enc oding.ASCII.Get String 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.En coding.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.En coding.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.Enc oding.ASCII.Get String 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.Defau lt' 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.Defau lt' 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.En coding.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
437
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 string that I sent into it. After working on Debugging the code I found two problems. One was in the statement fromEncrypt = New Byte(encrypted.Length) {} where both FromEncrypt and encrypted are both byte arrays and encrypted's length is 24....
43
4820
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 character set specifies that each character such as 'b' or 'B' is an 8 bit character. So what's a multibyte character? Also how would you use the function parameter main (char argc, char **argv) if that's correct? Bill
204
13117
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 = {0,1,2,4,9};
4
2437
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 unfortunate that i have to walk via System.String to do that. For instance, from an integer of value 123, i want:
3
276693
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
2007
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 FileOpen(2, "f:\aaapicture_album\result.txt", OpenMode.Binary FilePut(2, bytes FileClose(2 then convert it into a string --->
2
4514
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. Private Function byteArrayToString(ByVal byteArray() As Byte) As String Dim returnString As String = New String("") Dim i As Integer For i = 0 To byteArray.Length - 1 returnString += Chr(byteArray(i))
4
3397
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() (BinaryWriter.Write) from the string (String.ToCharArray), then use Stream.ToArray to convert everything to byte(). It works most of the time, but it happens that an error tells me something like "Additional information: Caractère de substitution faible trouvé...
11
5279
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 byte array. Can anyone help me ?
0
9632
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8958
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.