tags:

views:

23

answers:

1

I read in a Byte Array generated from a function called from an external DLL file and then converted (encoded) it into a String. In the Locals window (shown below), msg does not have a trailing double-quote.

Is this a bug, glitch, or a sign something is wrong?

Code:

    Dim msgC(32) As Byte
    Dim msg As String, length As Integer = 32

    HW(msgC, length)

    msg = System.Text.Encoding.Default.GetString(msgC)

    Dim x As String = "hi", y As String = " ho"
    Dim z As String = x & y

Locals:

msg     "Hello World    String
msgC    {Length=33}     Byte()
x       "hi"            String
y       " ho"           String
z       "hi ho"         String
+1  A: 

I suspect that this would happen if the string contains embedded null (\0, ASCII character code 0) characters.

SLaks
That was it! I changed the DLL to also send length and used `Substring` to trim the null characters.
Steven
Alternatively, you could use the overload of GetString() that has index and count paramters: http://msdn.microsoft.com/en-us/library/05cts4c3%28v=VS.100%29.aspx
Andy West
@Andy: Thank you!
Steven