the piece of code im working with is this:

// writing to network socket via binwriter

string test="hello";

bw_login.Write(test.PadRight(20,'!'));

this works fine, however when i substitute the above with
a static function

bw_login.Write(socketstring.pad("hello"));

the resulting output on my server has a "2" prepended to
the string ie: "2hello"

the function sockestring.pad looks like this:

public static string pad(string outstring)
{


return (outstring.PadRight(20,'!'));


}

am i missing something?

Re: wierd bug in binwriter?? (c#) by Jon

Jon
Thu Nov 06 09:56:10 CST 2003

thomas <ev8r@yahoo.com> wrote:
> the piece of code im working with is this:
>
> // writing to network socket via binwriter
>
> string test="hello";
>
> bw_login.Write(test.PadRight(20,'!'));
>
> this works fine, however when i substitute the above with
> a static function
>
> bw_login.Write(socketstring.pad("hello"));
>
> the resulting output on my server has a "2" prepended to
> the string ie: "2hello"

I suggest you have a close look at the documentation for BinaryWriter -
the string is prepended with the length. If you don't want this, you
probably don't really want to be using BinaryWriter.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too