Re: pls help: very odd behaviour when concatenating strings
From: Aaron (aza_rc_at_yahoo.com)
Date: 04/05/04
- Next message: Hans Kesting: "Re: mixing compact and winform code"
- Previous message: Jeffrey Tan[MSFT]: "Re: how do I find a hanging thread?"
- In reply to: Juan: "pls help: very odd behaviour when concatenating strings"
- Next in thread: Juan: "Re: pls help: very odd behaviour when concatenating strings"
- Reply: Juan: "Re: pls help: very odd behaviour when concatenating strings"
- Messages sorted by: [ date ] [ thread ]
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.
- Next message: Hans Kesting: "Re: mixing compact and winform code"
- Previous message: Jeffrey Tan[MSFT]: "Re: how do I find a hanging thread?"
- In reply to: Juan: "pls help: very odd behaviour when concatenating strings"
- Next in thread: Juan: "Re: pls help: very odd behaviour when concatenating strings"
- Reply: Juan: "Re: pls help: very odd behaviour when concatenating strings"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|