Re: pls help: very odd behaviour when concatenating strings

From: Aaron (aza_rc_at_yahoo.com)
Date: 04/05/04


Date: 5 Apr 2004 01:01:15 -0700

Juan,

More then likely you are having a problem because your byte array is
not full. As such every element that hasn't been assigned a byte will
be treated as 0 which messes things up when you convert the whole
array to a string.

You need to make sure whenever you do an operation on the array you
use the length of the array to limit the elements you are converting.
Example:

byte[] buffer = new byte[2048];
// Put some stuff in the buffer.
int bufferIndex = length of data placed in the buffer
string bufferString = System.Text.Encoding.ASCII.GetString(buffer, 0,
bufferIndex);

>From you code I am not sure what you are trying to do? You already
have a string but you are putting it into a byte array? If possible
you should use a StringBuilder object for string concetentaion
operations, it saves the inefficiency of creating new string objects
for each append.

Regards,

Aaron

"Juan" <juan_mauricio_lopez@ANTISPAMhotmail.com> wrote in message news:<O3F$AtqGEHA.704@tk2msftngp13.phx.gbl>...
> Does any one know if there are reported bugs when concatenating strings?
>
> When debugging each variable has the correct value but when I try to
> concatenate them some values are missing (I canīt see them in the debugger).
> After encoding the string (the sameone which complete value is not visible
> from the debugger) all the values can be seen but they are spaced by big
> amounts of zeros and use more that the 2048 bytes allocated. It is like if
> some of the string variables that I concatenate have a some "unused" space
> that can not be seen....
>
> Byte[] buffer = new Byte[2048]
> buffer = System.Text.Encoding.ASCII.GetBytes(string.ToCharArray());
>
> I hope I could made myself clear!
>
> Thanks,
>
> Juan.



Relevant Pages

  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: Data type byte
    ... attempt to change the input buffer to a string (although not by changing the ... With multi dimensional array that can hold ... Also the receiving ... dimensional Byte Array is just one long string of memory. ...
    (microsoft.public.vb.general.discussion)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)
  • RE: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)

Loading