BinaryWriter problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peyman

    #1

    BinaryWriter problem

    Hello all,
    This is my first c# program. And I seem to have a problem. Here is the
    code:

    FileStream myStream = new FileStream("d:\ \test.txt",
    FileMode.Create , FileAccess.Writ e);

    BinaryWriter writer = new BinaryWriter(my Stream);

    writer.Write("n testestse");
    writer.Close();

    In my text file I get a line feed 0x0a as the first char and then the
    string "ntestestse " (including the n). I have realised that if i
    change the string to test then I get a 0x09 (tab) as the first char in
    the file. so it seems to be related to the first char of my string.
    Any ideas???

    thanks
    Peyman Zehtab-Fard
  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: BinaryWriter problem

    Peyman,
    BinaryWriter writes strings as a counted (length prefixed) string. It writes
    one or more bytes of how many characters are in the string followed by the
    string.

    For details see the BinaryWriter.Wr ite(String) method &
    BinaryReader.Re adString methods:

    http://msdn.microsoft.com/library/de...iteTopic13.asp

    http://msdn.microsoft.com/library/de...tringTopic.asp

    Hope this helps
    Jay

    "Peyman" <peymanz@netsca pe.net> wrote in message
    news:69f851b4.0 310051644.1bf9f ac0@posting.goo gle.com...[color=blue]
    > Hello all,
    > This is my first c# program. And I seem to have a problem. Here is the
    > code:
    >
    > FileStream myStream = new FileStream("d:\ \test.txt",
    > FileMode.Create , FileAccess.Writ e);
    >
    > BinaryWriter writer = new BinaryWriter(my Stream);
    >
    > writer.Write("n testestse");
    > writer.Close();
    >
    > In my text file I get a line feed 0x0a as the first char and then the
    > string "ntestestse " (including the n). I have realised that if i
    > change the string to test then I get a 0x09 (tab) as the first char in
    > the file. so it seems to be related to the first char of my string.
    > Any ideas???
    >
    > thanks
    > Peyman Zehtab-Fard[/color]


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: BinaryWriter problem

      Peyman,
      BinaryWriter writes strings as a counted (length prefixed) string. It writes
      one or more bytes of how many characters are in the string followed by the
      string.

      For details see the BinaryWriter.Wr ite(String) method &
      BinaryReader.Re adString methods:

      http://msdn.microsoft.com/library/de...iteTopic13.asp

      http://msdn.microsoft.com/library/de...tringTopic.asp

      Hope this helps
      Jay

      "Peyman" <peymanz@netsca pe.net> wrote in message
      news:69f851b4.0 310051644.1bf9f ac0@posting.goo gle.com...[color=blue]
      > Hello all,
      > This is my first c# program. And I seem to have a problem. Here is the
      > code:
      >
      > FileStream myStream = new FileStream("d:\ \test.txt",
      > FileMode.Create , FileAccess.Writ e);
      >
      > BinaryWriter writer = new BinaryWriter(my Stream);
      >
      > writer.Write("n testestse");
      > writer.Close();
      >
      > In my text file I get a line feed 0x0a as the first char and then the
      > string "ntestestse " (including the n). I have realised that if i
      > change the string to test then I get a 0x09 (tab) as the first char in
      > the file. so it seems to be related to the first char of my string.
      > Any ideas???
      >
      > thanks
      > Peyman Zehtab-Fard[/color]


      Comment

      • Peyman Zehtab-Fard

        #4
        Re: BinaryWriter problem

        Thanks,
        I should have seen that. I am using StreamWriter now and all is working
        fine.

        Regards
        Peyman Zehtab-Fard

        "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@ema il.msn.com> wrote in message
        news:OWfRFD7iDH A.2160@TK2MSFTN GP12.phx.gbl...[color=blue]
        > Peyman,
        > BinaryWriter writes strings as a counted (length prefixed) string. It[/color]
        writes[color=blue]
        > one or more bytes of how many characters are in the string followed by the
        > string.
        >
        > For details see the BinaryWriter.Wr ite(String) method &
        > BinaryReader.Re adString methods:
        >
        >[/color]
        http://msdn.microsoft.com/library/de...iteTopic13.asp[color=blue]
        >
        >[/color]
        http://msdn.microsoft.com/library/de...tringTopic.asp[color=blue]
        >
        > Hope this helps
        > Jay
        >
        > "Peyman" <peymanz@netsca pe.net> wrote in message
        > news:69f851b4.0 310051644.1bf9f ac0@posting.goo gle.com...[color=green]
        > > Hello all,
        > > This is my first c# program. And I seem to have a problem. Here is the
        > > code:
        > >
        > > FileStream myStream = new FileStream("d:\ \test.txt",
        > > FileMode.Create , FileAccess.Writ e);
        > >
        > > BinaryWriter writer = new BinaryWriter(my Stream);
        > >
        > > writer.Write("n testestse");
        > > writer.Close();
        > >
        > > In my text file I get a line feed 0x0a as the first char and then the
        > > string "ntestestse " (including the n). I have realised that if i
        > > change the string to test then I get a 0x09 (tab) as the first char in
        > > the file. so it seems to be related to the first char of my string.
        > > Any ideas???
        > >
        > > thanks
        > > Peyman Zehtab-Fard[/color]
        >
        >[/color]


        Comment

        Working...