Home All Groups Group Topic Archive Search About
Author
7 Apr 2005 8:54 PM
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

Author
7 Apr 2005 9:32 PM
Oenone
LS wrote:
> 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,

--

(O) e n o n e
Author
7 Apr 2005 9:49 PM
Herfried K. Wagner [MVP]
"LS" <inva***@invalid.com> schrieb:
>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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
8 Apr 2005 5:49 PM
Jay B. Harlow [MVP - Outlook]
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

Show quoteHide quote
"LS" <inva***@invalid.com> wrote in message
news:OIV7JQ7OFHA.3380@TK2MSFTNGP15.phx.gbl...
|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
|
|