wierd bug in binwriter?? (c#)

  • Thread starter Thread starter thomas
  • Start date Start date
T

thomas

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?
 
thomas said:
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.
 
Back
Top