cannot append string

  • Thread starter Thread starter winthux
  • Start date Start date
W

winthux

I have something like this:
socket.Receive( buffor, 0, buffor.Length,
System.Net.Sockets.SocketFlags.None );

string tagS = System.Text.Encoding.ASCII.GetString( buffor );

// in tagS I have always tagS "<s i='404F8C46' c='1'>" , only i is changing

tagS += "</s>";

// this doesnt append tagS of the end tag and i dont know why, stays the
same. I have combined in very diffrent ways with chars, bytes and it happens
the same. Why ?
 
winthux said:
I have something like this:
socket.Receive( buffor, 0, buffor.Length,
System.Net.Sockets.SocketFlags.None );

string tagS = System.Text.Encoding.ASCII.GetString( buffor );

// in tagS I have always tagS "<s i='404F8C46' c='1'>" , only i is changing

tagS += "</s>";

// this doesnt append tagS of the end tag and i dont know why, stays the
same. I have combined in very diffrent ways with chars, bytes and it happens
the same. Why ?

I'm going to assume that you're looking at the contents of the tagS
string only using the debugger. The debugger has bug when showing string
contents - it stops displaying the contents when it hits a null
character. in .NET, strings can contain nulls, and I'll bet that buffor
contains some zeros after the valid character data.

You will probably need to strip the nulls from the tagS string before
doing further manipulation of it:

tagS = tagS.Replace( "\0", "");
 
winthux said:
I have something like this:
socket.Receive( buffor, 0, buffor.Length,
System.Net.Sockets.SocketFlags.None );

string tagS = System.Text.Encoding.ASCII.GetString( buffor );

The first problem here is that your socket.Receive might not have
returned a buffer's worth of data. You should only be decoding the
amount of data you receive - take note of the return value of
socket.Receive.
// in tagS I have always tagS "<s i='404F8C46' c='1'>" , only i is changing

tagS += "</s>";

// this doesnt append tagS of the end tag and i dont know why, stays the
same. I have combined in very diffrent ways with chars, bytes and it happens
the same. Why ?

It definitely *does* append it, but depending on hor you're viewing it,
if you have any trailing 0 characters (which could come from the
problem above) they may prevent any subsequent characters from being
seen.
 
Back
Top