New line code doesn't work

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

    New line code doesn't work

    Here is the code I have:

    String strCmd = "";

    strCmd = strCmd + "CREATE PROCEDURE GetAllModels2" + "\r\n";
    strCmd = strCmd + "AS";
    strCmd = strCmd + "BEGIN" + "\r\n";
    strCmd = strCmd + "SELECT * FROM tblModels" + "\r\n";
    strCmd = strCmd + "END" + "\r\n";
    strCmd = strCmd + "GO";

    When I look at strCmd in the command window, I still see the \r\n characters. I want new lines. Am I doing something wrong here?

    Thanks.

    STom



  • Richard A. Lowe

    #2
    Re: New line code doesn't work

    You're doing the right thing, the command window just shows strings that way
    (at least by default, maybe there's a way to change it?)

    --
    C#, .NET and Complex Adaptive Systems:

    "STom" <stombiztalker@ hotmail.com> wrote in message
    news:ucweBDy%23 EHA.3376@TK2MSF TNGP12.phx.gbl. ..
    Here is the code I have:

    String strCmd = "";
    strCmd = strCmd + "CREATE PROCEDURE GetAllModels2" + "\r\n";
    strCmd = strCmd + "AS";
    strCmd = strCmd + "BEGIN" + "\r\n";
    strCmd = strCmd + "SELECT * FROM tblModels" + "\r\n";
    strCmd = strCmd + "END" + "\r\n";
    strCmd = strCmd + "GO";
    When I look at strCmd in the command window, I still see the \r\n
    characters. I want new lines. Am I doing something wrong here?
    Thanks.
    STom


    Comment

    • yyy

      #3
      re:New line code doesn't work

      Try it with just "\n"

      *-----------------------*
      Posted at:

      *-----------------------*

      Comment

      • Nurchi BECHED

        #4
        Re: re:New line code doesn't work

        No, it is, by far, not redundant.
        If you open a text file, type something, save,
        and look at the file size, then add a new line
        by pressing Enter, you will notice, that file size
        increases by 2, not by 1.
        \r is caret return
        \n is a new line
        if one of them is missing, the file may open properly
        in one environment, but in another, you will see
        some crap (boxes or smth like that) at the end of lines...

        It is necessary.
        The best way to go is:
        <code>
        string NewLine=System. Environment.New Line;
        String strCmd = "";

        strCmd = strCmd + "CREATE PROCEDURE GetAllModels2" + NewLine;
        strCmd = strCmd + "AS";
        strCmd = strCmd + "BEGIN" + NewLine;
        strCmd = strCmd + "SELECT * FROM tblModels" + NewLine;
        strCmd = strCmd + "END" + NewLine;
        strCmd = strCmd + "GO";
        </code>
        And don't you need a new line or a space after "AS"?



        On Sat, 15 Jan 2005 23:56:15 +0100, Teis Draiby
        <teisREMOVE-THIS@draiby.com > wrote:
        [color=blue]
        > What is the reason that you normally use \r\n rather than always \n.
        > Isn't
        > that kindof... redundant?
        >
        > Teis
        >
        >
        >
        >
        > "yyy" <maxvizel@bezeq int-dot-net.no-spam.invalid> wrote in message
        > news:41e958cb$1 _2@Usenet.com.. .[color=green]
        >> Try it with just "\n"
        >>
        >> *-----------------------*
        >> Posted at:
        >> www.GroupSrv.com
        >> *-----------------------*[/color]
        >
        >[/color]



        --
        Regards,
        Nurchi BECHED

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: New line code doesn't work

          STom <stombiztalker@ hotmail.com> wrote:[color=blue]
          > Here is the code I have:
          >
          > String strCmd = "";
          >
          > strCmd = strCmd + "CREATE PROCEDURE GetAllModels2" + "\r\n";
          > strCmd = strCmd + "AS";
          > strCmd = strCmd + "BEGIN" + "\r\n";
          > strCmd = strCmd + "SELECT * FROM tblModels" + "\r\n";
          > strCmd = strCmd + "END" + "\r\n";
          > strCmd = strCmd + "GO";
          >
          > When I look at strCmd in the command window, I still see the \r\n
          > characters. I want new lines. Am I doing something wrong here?[/color]

          See http://www.pobox.com/~skeet/csharp/s....html#debugger

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          Working...