473,495 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding

The reason I want to do so, is that I am sending to DOS and I am pretty
certain that it will not work.
Everything I've tried so far hasnt.

In my test environment (Windows to Windows) this works perfectly, but not
when sending to DOS:

Private Function bytearray2string(ByVal input As Byte()) As String

Dim output As String

output = System.Text.Encoding.Default.GetString(input)

Return output

End Function

Private Function string2bytearray(ByVal input As String) As Byte()

Dim output() As Byte

output = System.Text.Encoding.Default.GetBytes(input)

Return output

End Function

I have also tried this, to no avail in Windows:

Private Function bytearray2string2(ByVal input As Byte()) As String

Dim output As String = ""

Dim i As Integer = 0

'Dim vchar As Char

While i < input.Length

output = output & CChar(Chr(input.GetValue(i)))

i = i + 1

End While

Return (output)

End Function

Private Function string2bytearray2(ByVal input As String) As Byte()

Dim output(input.Length - 1) As Byte

Dim i As Integer = 0

For i = 0 To UBound(output)

output(i) = CByte(Asc(input.Chars(i)))

Next

Return (output)

End Function

The desired functions need to use no encoding and be able to work with
simple bytes. The values I'll be receiving wont be higher anyway.

I'd appreciate any feedback whatsoever.

regards,
J

Nov 20 '05 #1
4 6685
Why not use ASCII encoding, instead of 'Default'

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
"I.Charitopoulos" <i.*************@mellon.com.gr> wrote in message
news:#E**************@TK2MSFTNGP09.phx.gbl...
The reason I want to do so, is that I am sending to DOS and I am pretty
certain that it will not work.
Everything I've tried so far hasnt.

In my test environment (Windows to Windows) this works perfectly, but not
when sending to DOS:

Private Function bytearray2string(ByVal input As Byte()) As String

Dim output As String

output = System.Text.Encoding.Default.GetString(input)

Return output

End Function

Private Function string2bytearray(ByVal input As String) As Byte()

Dim output() As Byte

output = System.Text.Encoding.Default.GetBytes(input)

Return output

End Function

I have also tried this, to no avail in Windows:

Private Function bytearray2string2(ByVal input As Byte()) As String

Dim output As String = ""

Dim i As Integer = 0

'Dim vchar As Char

While i < input.Length

output = output & CChar(Chr(input.GetValue(i)))

i = i + 1

End While

Return (output)

End Function

Private Function string2bytearray2(ByVal input As String) As Byte()

Dim output(input.Length - 1) As Byte

Dim i As Integer = 0

For i = 0 To UBound(output)

output(i) = CByte(Asc(input.Chars(i)))

Next

Return (output)

End Function

The desired functions need to use no encoding and be able to work with
simple bytes. The values I'll be receiving wont be higher anyway.

I'd appreciate any feedback whatsoever.

regards,
J


Nov 20 '05 #2
ASCII Encoding uses 7 bits out of the byte, so I'd be losing 1 bit out of
every byte of data that comes in.

I want to use the extended ASCII that uses all 8 bits, for values of 0 to
255.
"Tom Spink" <th**********@ntlworld.com> wrote in message
news:#1**************@TK2MSFTNGP09.phx.gbl...
Why not use ASCII encoding, instead of 'Default'

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit


Nov 20 '05 #3
"I.Charitopoulos" <i.*************@mellon.com.gr> schrieb
The reason I want to do so, is that I am sending to DOS and I am
pretty certain that it will not work.
Everything I've tried so far hasnt.

In my test environment (Windows to Windows) this works perfectly, but
not when sending to DOS:
[...]


Maybe codepage 850 is what you're looking for.

System.Text.Encoding.GetEncoding(850)

Use it to convert from/to byte arrays. There are other codepages

See also:
http://www.microsoft.com/globaldev/r...ce/cphome.mspx

To find the right encoding, open a DOS window and enter
mode con cp<enter>

Should return the encoding you need (but I'm not sure)

--
Armin

Nov 20 '05 #4
Thanx a lot for the tip. Will try that.

Seems like a reliable way of getting the encoding.
Maybe codepage 850 is what you're looking for.

System.Text.Encoding.GetEncoding(850)

Use it to convert from/to byte arrays. There are other codepages

See also:
http://www.microsoft.com/globaldev/r...ce/cphome.mspx

To find the right encoding, open a DOS window and enter
mode con cp<enter>

Should return the encoding you need (but I'm not sure)

--
Armin

Nov 20 '05 #5

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

Similar topics

4
3557
by: Ching-Lung | last post by:
Hi, I have web browser control in my windows form and am implementing the following event: ***************************************** public void BeforeNavigate(string URL, int Flags, string...
15
2528
by: C# Learner | last post by:
Hi, I have a string (System.String) which holds some data. This data is encoding in UTF8 (i.e. anywhere in the string where there should be a single 'é' character, there will be two characters...
2
3799
by: Chris Millar | last post by:
Can anyone help me on converting this vb asp page to C#, thanks in advance. chris. <!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.0 transitional//EN"> <%...
15
2399
by: Peter Afonin | last post by:
Hello, I'm struggling with the string conversion to MD5 which I've never user before. I have a string that I need to encode which looks approximately like this: ...
5
2264
by: Kasper Hansen | last post by:
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...
18
34066
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
6
18028
by: msdnuniv | last post by:
Hello everybody, since days i try to convert Unicode-Strings in VB.NET to ANSI which should be processable in VB6 and converted to unicode again. It should be possible with any codepage, e.g....
4
5640
by: | last post by:
Hi all, I want to create a method that does the following: 1) Programmatically instantiate a new XmlDataSource control 2) For each file in a named directory, make a "FileSystemItem" element 3)...
4
2214
by: vcnewbie | last post by:
Hi I'm maintaining a VisualC++ project to increase its security regarding stored passwords. I thought about using SHA256Managed to create a hash for the password when creating a user and when...
0
7120
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
6991
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...
0
7196
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...
1
6878
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
7373
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
5456
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,...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
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...

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.