473,387 Members | 1,582 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,387 software developers and data experts.

System.Byte() array convert to string... HOW???

Using the VB6 Winsock control in VB.NET the GetData(byRef Data as Object) method of the control returns an Object.

I have used this code that works but am not familiar with .NET arrays/object/conversions...

Private Sub wskSocketPlus_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrival Event) Handles wskSocketPlus.DataArrival

Dim o As Object
wskSocketPlus.GetData(o)
Dim incomingDataArray() As Byte
incomingDataArray = CType(o, System.Byte())

Dim Buffer As New StringBuilder
Dim b As Byte

For element As Integer = 0 To incomingDataArray.Length - 1
b = Convert.ToByte(incomingDataArray.GetValue(element) )
Buffer.Append(Chr(b))
Next element

MessageBox.Show(Buffer.ToString)

End Sub

I was told I should use string builder as it is fatser than concatination. The datapackets are around a few thosand bytes. Any suggestions as to a more correct set of conversions to give me a resulting string of the incoming Object data?

thanks, Jarrod
Jul 21 '05 #1
2 9198
this worked as well.... but geez.... why no GetData(string) ??

Dim o As Object
AxWinsock2.GetData(o)

Dim b() As Byte
b = CType(o, Byte())

Dim a As ASCIIEncoding
a = New ASCIIEncoding

Dim s As String
s = a.GetString(b)

MessageBox.Show(s)
Jul 21 '05 #2
Jarrod Sharp <Ja*********@discussions.microsoft.com> wrote:
this worked as well.... but geez.... why no GetData(string) ??


Because a socket is a fundamentally binary object. I think it's great
that the framework makes such a clear distinction between binary data
and character data.

Note that you don't need to create a new instance of ASCIIEncoding
yourself - just use the Encoding.ASCII property.

(I'd also suggest using the Socket class that's built into the
framework, btw - or even TcpClient.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3

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

Similar topics

2
by: Mark | last post by:
Sorry about the last... Anyway, here's the question: I've been working on some C# routines to process strings in and out of various encodings. The hope is that I can just let the user type in...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
4
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...
2
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...
5
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of...
8
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
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...
14
by: ThazKool | last post by:
I want to see if this code works the way it should on a Big-Endian system. Also if anyone has any ideas on how determine this at compile-time so that I use the right decoding or encoding...
10
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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,...

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.