New line code doesn't work

  • Thread starter Thread starter STom
  • Start date Start date
S

STom

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
 
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:
http://blogs.geekdojo.net/Richard
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
 
What is the reason that you normally use \r\n rather than always \n. Isn't
that kindof... redunant?

Teis
 
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.NewLine;
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"?
 
STom said:
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?

See http://www.pobox.com/~skeet/csharp/strings.html#debugger
 
Back
Top