473,651 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Byte Array to String

AG
I have a file that contains ASCII and Extended ASCII characters.
I need to get the file contents into a string, but the Extended ASCII
characters (dec 128 and 129) are being changed to dec 63.

I have tried several methods, but here is the one I thought would have
worked.

Dim strReturn As String
Dim arBytes() As Byte
arBytes = System.IO.File. ReadAllBytes(<m yfile>)
strReturn = System.Text.Enc oding.UTF8.GetS tring(arBytes)

When I examine strReturn, I find that the chars that should be chr(128) and
chr(129) are all chr(63).

The only thing I could get to work is

Dim strReturn As String = String.Empty
Dim arBytes() As Byte
Dim sB As New StringBuilder
Dim byT As Byte

arBytes = System.IO.File. ReadAllBytes(st rPathFile)
For Each byT In arBytes
sB.Append(Chr(b yT))
Next
strReturn = sB.ToString

Can anyone offer an explanation, and/or a better method?

--

AG
Email: discussATadhdat aDOTcom
Nov 22 '07 #1
6 2165
i use this to read file contents

Public Function GetFileContents (ByVal FullPath As String, _
Optional ByRef ErrInfo As String = "") As String

Dim strContents As String
Dim objReader As StreamReader
Try

objReader = New StreamReader(Fu llPath)
strContents = objReader.ReadT oEnd()
objReader.Close ()
Return strContents
Catch Ex As Exception
ErrInfo = Ex.Message
Return Nothing
End Try
End Function

On Nov 22, 11:56 am, "AG" <NOSPAMa-g...@newsgroups .nospamwrote:
I have a file that contains ASCII and Extended ASCII characters.
I need to get the file contents into a string, but the Extended ASCII
characters (dec 128 and 129) are being changed to dec 63.

I have tried several methods, but here is the one I thought would have
worked.

Dim strReturn As String
Dim arBytes() As Byte
arBytes = System.IO.File. ReadAllBytes(<m yfile>)
strReturn = System.Text.Enc oding.UTF8.GetS tring(arBytes)

When I examine strReturn, I find that the chars that should be chr(128) and
chr(129) are all chr(63).

The only thing I could get to work is

Dim strReturn As String = String.Empty
Dim arBytes() As Byte
Dim sB As New StringBuilder
Dim byT As Byte

arBytes = System.IO.File. ReadAllBytes(st rPathFile)
For Each byT In arBytes
sB.Append(Chr(b yT))
Next
strReturn = sB.ToString

Can anyone offer an explanation, and/or a better method?

--

AG
Email: discussATadhdat aDOTcom
Nov 22 '07 #2
Look at the Encoding object, as it is the quickest. THe other method is some
form of loop, as suggested by Nick.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************** *************** *************** ****
| Think outside the box!
|
*************** *************** *************** ****
"AG" <NO**********@n ewsgroups.nospa mwrote in message
news:eM******** ******@TK2MSFTN GP02.phx.gbl...
>I have a file that contains ASCII and Extended ASCII characters.
I need to get the file contents into a string, but the Extended ASCII
characters (dec 128 and 129) are being changed to dec 63.

I have tried several methods, but here is the one I thought would have
worked.

Dim strReturn As String
Dim arBytes() As Byte
arBytes = System.IO.File. ReadAllBytes(<m yfile>)
strReturn = System.Text.Enc oding.UTF8.GetS tring(arBytes)

When I examine strReturn, I find that the chars that should be chr(128)
and chr(129) are all chr(63).

The only thing I could get to work is

Dim strReturn As String = String.Empty
Dim arBytes() As Byte
Dim sB As New StringBuilder
Dim byT As Byte

arBytes = System.IO.File. ReadAllBytes(st rPathFile)
For Each byT In arBytes
sB.Append(Chr(b yT))
Next
strReturn = sB.ToString

Can anyone offer an explanation, and/or a better method?

--

AG
Email: discussATadhdat aDOTcom

Nov 22 '07 #3
AG
Thanks Nick.
That is one of the methods that I tried which does not produce the desired
results.

--

AG
Email: discussATadhdat aDOTcom
"Nick Chan" <zz*******@yaho o.comwrote in message
news:fb******** *************** ***********@e23 g2000prf.google groups.com...
>i use this to read file contents

Public Function GetFileContents (ByVal FullPath As String, _
Optional ByRef ErrInfo As String = "") As String

Dim strContents As String
Dim objReader As StreamReader
Try

objReader = New StreamReader(Fu llPath)
strContents = objReader.ReadT oEnd()
objReader.Close ()
Return strContents
Catch Ex As Exception
ErrInfo = Ex.Message
Return Nothing
End Try
End Function

On Nov 22, 11:56 am, "AG" <NOSPAMa-g...@newsgroups .nospamwrote:
>I have a file that contains ASCII and Extended ASCII characters.
I need to get the file contents into a string, but the Extended ASCII
characters (dec 128 and 129) are being changed to dec 63.

I have tried several methods, but here is the one I thought would have
worked.

Dim strReturn As String
Dim arBytes() As Byte
arBytes = System.IO.File. ReadAllBytes(<m yfile>)
strReturn = System.Text.Enc oding.UTF8.GetS tring(arBytes)

When I examine strReturn, I find that the chars that should be chr(128)
and
chr(129) are all chr(63).

The only thing I could get to work is

Dim strReturn As String = String.Empty
Dim arBytes() As Byte
Dim sB As New StringBuilder
Dim byT As Byte

arBytes = System.IO.File. ReadAllBytes(st rPathFile)
For Each byT In arBytes
sB.Append(Chr(b yT))
Next
strReturn = sB.ToString

Can anyone offer an explanation, and/or a better method?

--

AG
Email: discussATadhdat aDOTcom

Nov 22 '07 #4
AG
Thanks Gregory.
I have looked at it and tried several different methods. I guess I don't
understand it well enough.

--

AG
Email: discussATadhdat aDOTcom
"Cowboy (Gregory A. Beamer)" <No************ @comcast.netNoS pamMwrote in
message news:%2******** **********@TK2M SFTNGP02.phx.gb l...
Look at the Encoding object, as it is the quickest. THe other method is
some form of loop, as suggested by Nick.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************** *************** *************** ****
| Think outside the box! |
*************** *************** *************** ****
"AG" <NO**********@n ewsgroups.nospa mwrote in message
news:eM******** ******@TK2MSFTN GP02.phx.gbl...
>>I have a file that contains ASCII and Extended ASCII characters.
I need to get the file contents into a string, but the Extended ASCII
characters (dec 128 and 129) are being changed to dec 63.

I have tried several methods, but here is the one I thought would have
worked.

Dim strReturn As String
Dim arBytes() As Byte
arBytes = System.IO.File. ReadAllBytes(<m yfile>)
strReturn = System.Text.Enc oding.UTF8.GetS tring(arBytes)

When I examine strReturn, I find that the chars that should be chr(128)
and chr(129) are all chr(63).

The only thing I could get to work is

Dim strReturn As String = String.Empty
Dim arBytes() As Byte
Dim sB As New StringBuilder
Dim byT As Byte

arBytes = System.IO.File. ReadAllBytes(st rPathFile)
For Each byT In arBytes
sB.Append(Chr(b yT))
Next
strReturn = sB.ToString

Can anyone offer an explanation, and/or a better method?

--

AG
Email: discussATadhdat aDOTcom


Nov 22 '07 #5
You probably need the figure out what the codepage of the ASCII file is.

It is probably 437 or 850 (if you are american of westeuropian), but other
are also possible.
Most likely it depends where you are located.

GetEncoding("cp 437") of something like that should give you the encoding.

Henk
"AG" <NO**********@n ewsgroups.nospa mwrote in message
news:eM******** ******@TK2MSFTN GP02.phx.gbl...
>I have a file that contains ASCII and Extended ASCII characters.
I need to get the file contents into a string, but the Extended ASCII
characters (dec 128 and 129) are being changed to dec 63.

I have tried several methods, but here is the one I thought would have
worked.

Dim strReturn As String
Dim arBytes() As Byte
arBytes = System.IO.File. ReadAllBytes(<m yfile>)
strReturn = System.Text.Enc oding.UTF8.GetS tring(arBytes)

When I examine strReturn, I find that the chars that should be chr(128)
and chr(129) are all chr(63).

The only thing I could get to work is

Dim strReturn As String = String.Empty
Dim arBytes() As Byte
Dim sB As New StringBuilder
Dim byT As Byte

arBytes = System.IO.File. ReadAllBytes(st rPathFile)
For Each byT In arBytes
sB.Append(Chr(b yT))
Next
strReturn = sB.ToString

Can anyone offer an explanation, and/or a better method?

--

AG
Email: discussATadhdat aDOTcom

Nov 22 '07 #6
AG
Thanks Henk.

Neither 437 or 850 worked, but you put me on the right track.
1252 did work!

--

AG
Email: discussATadhdat aDOTcom
"Henk Kelder" <hk*****@versat el.nlwrote in message
news:47******** **************@ news.tele2.nl.. .
You probably need the figure out what the codepage of the ASCII file is.

It is probably 437 or 850 (if you are american of westeuropian), but other
are also possible.
Most likely it depends where you are located.

GetEncoding("cp 437") of something like that should give you the encoding.

Henk
"AG" <NO**********@n ewsgroups.nospa mwrote in message
news:eM******** ******@TK2MSFTN GP02.phx.gbl...
>>I have a file that contains ASCII and Extended ASCII characters.
I need to get the file contents into a string, but the Extended ASCII
characters (dec 128 and 129) are being changed to dec 63.

I have tried several methods, but here is the one I thought would have
worked.

Dim strReturn As String
Dim arBytes() As Byte
arBytes = System.IO.File. ReadAllBytes(<m yfile>)
strReturn = System.Text.Enc oding.UTF8.GetS tring(arBytes)

When I examine strReturn, I find that the chars that should be chr(128)
and chr(129) are all chr(63).

The only thing I could get to work is

Dim strReturn As String = String.Empty
Dim arBytes() As Byte
Dim sB As New StringBuilder
Dim byT As Byte

arBytes = System.IO.File. ReadAllBytes(st rPathFile)
For Each byT In arBytes
sB.Append(Chr(b yT))
Next
strReturn = sB.ToString

Can anyone offer an explanation, and/or a better method?

--

AG
Email: discussATadhdat aDOTcom


Nov 23 '07 #7

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

Similar topics

5
13915
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do something like: char chars = "Hello!"; byte bytes = (byte) chars;
8
8220
by: Dmitri Shvetsov | last post by:
Hi All, Did somebody try to get the Hash code from byte array? The method exists, the program is compilable but...))) Try!-) Every time you can get the different code from the same array, and always very short, like in range from 10 to 18 in my case. Maybe this method has no realization? P.S. To get a correct result I use transformation of byte to string and
3
9505
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At the end of this message is the inflate method this is where I get stuck I know that I need a byte array but because I am decompressing a string I have no idea of how big the byte array will need to be in the end (the inflate and deflate methods...
8
10706
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to receive a byte array as one of its parameters. The project is marked for COM interop, and that all proceeds normally. When I reference the type library in the VB6 project, and write the code to call the function that returns the byte array, it works
4
13397
by: David Bargna | last post by:
Hi I have a problem, I have a string which needs to be converted to a byte array, then have the string representation of this array stored in an AD attribute. This string attribute then has to be read and the string representation of the byte array has to be converted back to the original byte array and converted back to the original string - confused yet? in psuedo
2
3578
by: Bryan | last post by:
Apologies if this is a noob question, but I've been struggling with this for quite a while... I'm trying to convert a byte array (encrypted authorization code) into a *screen-printable* string that is displayed in a text box. Once displayed, the text will be copied, transmitted and then pasted (all manually by humans) into a second utility where the string must then be reverse-engineered into the *original* byte array. The byte array will...
6
53702
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how do I convert it to: dim myStr as string = "11,22,33,44"
4
3391
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é...
10
2673
by: Danny | last post by:
I am working on a project where I will receive xml documents from clients machines as a byte array. They will use the web browser navigate method to post the data to my ASP.NET page. I then pick up the byte array using the request object (XMLData=bytearray..). Can someone point me to an article that shows me how I can do this in ASP.NET, C#? Thanks Danny
17
7239
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need to show the array data to the end user. Can I do that? How?
0
8352
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
8275
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
8697
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
8465
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,...
1
6158
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
4144
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
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.