conversion issue

  • Thread starter Thread starter LS
  • Start date Start date
L

LS

I use winpcap in dotnet to capture packets from the wire.
I have them in a byte() array. (variable rawbytes())
How do I convert them to a readable string?

I have for example following values
0,208,65,11,96,147,0,6,91,184, ...

I tried

For i = 0 To Packethdr.Caplength - 1
ch = System.Convert.ToChar(Rawbytes(i))
str.Concat(ch.ToString)
Next

This return an empty string.
Can anybody help me?

Regards

Geert
 
LS said:
I use winpcap in dotnet to capture packets from the wire.
I have them in a byte() array. (variable rawbytes())
How do I convert them to a readable string?

You can use the System.Text.Encoding.ASCII.GetString() method to convert a
byte-array to a string, as follows:

Dim b As Byte() = {65, 66, 67, 68, 69}
Dim s As String
s = System.Text.Encoding.ASCII.GetString(b)
MsgBox(s)

Hope that helps,
 
LS said:
I use winpcap in dotnet to capture packets from the wire.
I have them in a byte() array. (variable rawbytes())
How do I convert them to a readable string?

Take a look at the 'System.Text.Encoding.<encoding name>.GetString' methods.
Notice that 'String.Concat' is a /shared/ method which will /return/ the
result of the concatenation.
 
Geert,
As the others suggest use the appropriate System.Text.Encoding object for
the character encoding that you are receiving.

| 0,208,65,11,96,147,0,6,91,184, ...
| This return an empty string.
| Can anybody help me?
Your string is not empty per se, however the Debugger will make it appear it
is, as your first & seventh characters are ChrW(0) which the debugger treats
as a string terminator. In addition to the debugger a number of Win32 APIs
that you may call via P/Invoke (Declare statements) will also treat ChrW(0)
as a string terminator. System.String itself however treats ChrW(0) as any
other valid character.

Hope this helps
Jay

|I use winpcap in dotnet to capture packets from the wire.
| I have them in a byte() array. (variable rawbytes())
| How do I convert them to a readable string?
|
| I have for example following values
| 0,208,65,11,96,147,0,6,91,184, ...
|
| I tried
|
| For i = 0 To Packethdr.Caplength - 1
| ch = System.Convert.ToChar(Rawbytes(i))
| str.Concat(ch.ToString)
| Next
|
| This return an empty string.
| Can anybody help me?
|
| Regards
|
| Geert
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top