String includes RETURN KEY

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

    #1

    String includes RETURN KEY

    hi, all.

    Here is a stupid question.

    I have three string
    string str1 =" test1 ";
    string str2 =" test21\ntest22\ ntest23"; (\n means return key)
    string str3 =" test3 ";
    I write them to a file(test.txt) by using Stream.write();
    I open the file:
    it is:
    test1
    test21
    test22
    test23
    test3
    when I read test.txtby using Stream.read(), I can not restore it again.I got
    5 string.
    indeed, It should three string?

    What should I do?

    Thanks







  • Peter Rilling

    #2
    Re: String includes RETURN KEY

    Can you provide more code. Streams work on bytes and there is no concept of
    "5 string" since you are simply requesting the number of bytes. Are you
    actually using a StreamReader or something?

    "jeff" <jeff@discussio ns.microsoft.co m> wrote in message
    news:17ECDAC6-4524-4879-8254-0818E76B77F0@mi crosoft.com...[color=blue]
    > hi, all.
    >
    > Here is a stupid question.
    >
    > I have three string
    > string str1 =" test1 ";
    > string str2 =" test21\ntest22\ ntest23"; (\n means return key)
    > string str3 =" test3 ";
    > I write them to a file(test.txt) by using Stream.write();
    > I open the file:
    > it is:
    > test1
    > test21
    > test22
    > test23
    > test3
    > when I read test.txtby using Stream.read(), I can not restore it again.I[/color]
    got[color=blue]
    > 5 string.
    > indeed, It should three string?
    >
    > What should I do?
    >
    > Thanks
    >
    >
    >
    >
    >
    >
    >[/color]


    Comment

    • mgooley

      #3
      RE: String includes RETURN KEY



      "jeff" wrote:
      [color=blue]
      > hi, all.
      >
      > Here is a stupid question.
      >
      > I have three string
      > string str1 =" test1 ";
      > string str2 =" test21\ntest22\ ntest23"; (\n means return key)
      > string str3 =" test3 ";
      > I write them to a file(test.txt) by using Stream.write();
      > I open the file:
      > it is:
      > test1
      > test21
      > test22
      > test23
      > test3
      > when I read test.txtby using Stream.read(), I can not restore it again.I got
      > 5 string.
      > indeed, It should three string?
      >
      > What should I do?
      >
      > Thanks
      >
      >
      >
      >
      >
      >
      >[/color]

      Comment

      • mgooley

        #4
        RE: String includes RETURN KEY


        try using the "@" literal string character in front of str2.
        I did not try it but its an idea.

        "jeff" wrote:
        [color=blue]
        > hi, all.
        >
        > Here is a stupid question.
        >
        > I have three string
        > string str1 =" test1 ";
        > string str2 =" test21\ntest22\ ntest23"; (\n means return key)
        > string str3 =" test3 ";
        > I write them to a file(test.txt) by using Stream.write();
        > I open the file:
        > it is:
        > test1
        > test21
        > test22
        > test23
        > test3
        > when I read test.txtby using Stream.read(), I can not restore it again.I got
        > 5 string.
        > indeed, It should three string?
        >
        > What should I do?
        >
        > Thanks
        >
        >
        >
        >
        >
        >
        >[/color]

        Comment

        • Michael A. Covington

          #5
          Re: String includes RETURN KEY

          \n *is* the end of a line and is working correctly.

          How can you want some of your ends of lines not to be ends of lines?

          But if what you mean is that you want to preserve the strings, I suppose you
          could convert every end of line mark to something else before writing the
          string out, and undo the conversion after reading it in again.


          "jeff" <jeff@discussio ns.microsoft.co m> wrote in message
          news:17ECDAC6-4524-4879-8254-0818E76B77F0@mi crosoft.com...[color=blue]
          > hi, all.
          >
          > Here is a stupid question.
          >
          > I have three string
          > string str1 =" test1 ";
          > string str2 =" test21\ntest22\ ntest23"; (\n means return key)
          > string str3 =" test3 ";
          > I write them to a file(test.txt) by using Stream.write();
          > I open the file:
          > it is:
          > test1
          > test21
          > test22
          > test23
          > test3
          > when I read test.txtby using Stream.read(), I can not restore it again.I
          > got
          > 5 string.
          > indeed, It should three string?
          >
          > What should I do?
          >
          > Thanks
          >
          >
          >
          >
          >
          >
          >[/color]


          Comment

          • yaniv abo

            #6
            Re: String includes RETURN KEY

            if you want new line Use :
            "\r\n" - new line in windows
            ( '\n' = new line in Linux , '\r' = new line in Mac)
            If you what '\n' in the file Use "\\n"

            "jeff" <jeff@discussio ns.microsoft.co m> wrote in message
            news:17ECDAC6-4524-4879-8254-0818E76B77F0@mi crosoft.com...[color=blue]
            > hi, all.
            >
            > Here is a stupid question.
            >
            > I have three string
            > string str1 =" test1 ";
            > string str2 =" test21\ntest22\ ntest23"; (\n means return key)
            > string str3 =" test3 ";
            > I write them to a file(test.txt) by using Stream.write();
            > I open the file:
            > it is:
            > test1
            > test21
            > test22
            > test23
            > test3
            > when I read test.txtby using Stream.read(), I can not restore it again.I
            > got
            > 5 string.
            > indeed, It should three string?
            >
            > What should I do?
            >
            > Thanks
            >
            >
            >
            >
            >
            >
            >[/color]


            Comment

            Working...