473,508 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

csharp IDE long lines to code to multiline

Hi,

im using csharp express 2005.

I have a problem in the IDE, when i have along line of code or a long
line of text in a static string, i want to make it multi line for
easir readability, but using <returnor <shift returndosnt seem to
allow for breaking long code lines into mutliline and still compile

Im sure ive seen this done, but how is it done in the ide ?

thanks

Peted
May 9 '07 #1
13 6990
With strings, you have two basic options:

a: use the @ prefix and include returns in the string - i.e.

string longString = @"this is a
long string that contains
line breaks";

or b: use a few strings (in the source), and let the compiler stitch
them together, i.e.

string longString = "this is a\n" +
"long string that contains\n" +
"line breaks";

Any use?

Marc
May 9 '07 #2
that should have occured to me thanks.

what about long lines of c# code, not that that will be a comman
problem, but im curious just in case i end up with a long line of
actual c# code, is there any way to make that multi line and still
compile?
thanks

Peted

On Wed, 9 May 2007 10:45:48 +0100, "Marc Gravell"
<ma**********@gmail.comwrote:
>With strings, you have two basic options:

a: use the @ prefix and include returns in the string - i.e.

string longString = @"this is a
long string that contains
line breaks";

or b: use a few strings (in the source), and let the compiler stitch
them together, i.e.

string longString = "this is a\n" +
"long string that contains\n" +
"line breaks";

Any use?

Marc
May 9 '07 #3
c# is free-form; only a few things (literals, comments etc) are fussy
about line breaks; the following compiles just fine (but is ugly as
sin ;-p):
foreach
(
char
c
in
"abcdef"
) {
Console.WriteLine
(
c);
}

Marc
May 9 '07 #4
<Petedwrote:
that should have occured to me thanks.

what about long lines of c# code, not that that will be a comman
problem, but im curious just in case i end up with a long line of
actual c# code, is there any way to make that multi line and still
compile?
You can generally just break it between any two parts, e.g.

someReference.CallSomeMethod("First parameter",
"Second parameter")
.CallAnotherMethod("...");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 9 '07 #5
On 9 Maj, 11:45, "Marc Gravell" <marc.grav...@gmail.comwrote:
[...]
string longString = "this is a\n" +
"long string that contains\n" +
"line breaks";
[...]
I tend to prefer a use a string br = Environment.NewLine instead of
\n, just in case.

using System;
using System.Text;

class Program
{
static void Main(string[] args)
{
string br = Environment.NewLine;

string foo = "abra" + br
+ "kadabra" + br
+ "ala kazam";

Console.WriteLine(foo);
}
}

/Per

--

Per Erik Strandberg
Tomlab Optimization Inc.
http://tomopt.com/tomnet/

May 9 '07 #6

HAHA, ok i see, its only the strings i need to worry about

dont know how i missed all that.

thanks
Peted
On Wed, 9 May 2007 11:03:59 +0100, Jon Skeet [C# MVP]
<sk***@pobox.comwrote:
<Petedwrote:
>that should have occured to me thanks.

what about long lines of c# code, not that that will be a comman
problem, but im curious just in case i end up with a long line of
actual c# code, is there any way to make that multi line and still
compile?

You can generally just break it between any two parts, e.g.

someReference.CallSomeMethod("First parameter",
"Second parameter")
.CallAnotherMethod("...");
May 9 '07 #7
Just note that this pushes concatenation into run-time rather than
compile-time, since this isn't a constant... just something to note in
a tight loop ;-p

Marc
May 9 '07 #8
per9000 wrote:
I tend to prefer a use a string br = Environment.NewLine instead of
\n, just in case.
I think that is good advice. In a Windows system Environment.NewLine
does not contain "\n" but "\r\n".

As Marc pointed out, the compiler will most probably not be able to
concatenate the strings at compile time.

However, it's questionable if string literals should even contain line
breaks. Perhaps an array of strings is a better way to represent data
like this, and adding the line breaks by using WriteLine to write each
string. :)

--
Göran Andersson
_____
http://www.guffa.com
May 9 '07 #9
Göran Andersson <gu***@guffa.comwrote:
per9000 wrote:
I tend to prefer a use a string br = Environment.NewLine instead of
\n, just in case.
I think that is good advice. In a Windows system Environment.NewLine
does not contain "\n" but "\r\n".

As Marc pointed out, the compiler will most probably not be able to
concatenate the strings at compile time.

However, it's questionable if string literals should even contain line
breaks. Perhaps an array of strings is a better way to represent data
like this, and adding the line breaks by using WriteLine to write each
string. :)
It all depends on what you're doing with it. If you're writing to the
console, then yes - but if you're getting the data ready to go down a
socket, then:
a) It makes sense to use a single string and encode it once
b) You need to make sure you use the appropriate line termination for
the protocol, rather than using Environment.NewLine.

It's certainly not the case that everywhere you see \n or \r\n you
should replace it with a call to Environment.NewLine.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 9 '07 #10
On May 9, 5:40 am, Peted wrote:
Hi,

im using csharp express 2005.

I have a problem in the IDE, when i have along line of code or a long
line of text in a static string, i want to make it multi line for
easir readability, but using <returnor <shift returndosnt seem to
allow for breaking long code lines into mutliline and still compile

Im sure ive seen this done, but how is it done in the ide ?

thanks

Peted
Why not just put the string in a resource file? Goto the project
properties page, click the Resources tab. If you don't have one,
there will be a link to create one. Click it, and off you go. Then
you can reference the string like so:

MessageBox.Show( Properties.Resources.MyLongString );

May 9 '07 #11
"Jon Skeet [C# MVP]" <sk***@pobox.comschrieb im Newsbeitrag
news:MP********************@msnews.microsoft.com.. .
>However, it's questionable if string literals should even contain line
breaks. Perhaps an array of strings is a better way to represent data
like this, and adding the line breaks by using WriteLine to write each
string. :)

It all depends on what you're doing with it. If you're writing to the
console, then yes - but if you're getting the data ready to go down a
socket, then:
a) It makes sense to use a single string and encode it once
b) You need to make sure you use the appropriate line termination for
the protocol, rather than using Environment.NewLine.
So, what should I use ? MyProtocol.NewLine ? ;-)
It's certainly not the case that everywhere you see \n or \r\n you
should replace it with a call to Environment.NewLine.
But when shall one use it and when not?

Christof
May 9 '07 #12
"Andy" <an***@med-associates.comschrieb im Newsbeitrag
news:11**********************@o5g2000hsb.googlegro ups.com...
>
Why not just put the string in a resource file? Goto the project
properties page, click the Resources tab. If you don't have one,
there will be a link to create one. Click it, and off you go. Then
you can reference the string like so:
This surely is the right place for UI-Strings, wich will change with the
language/culture.
But there are other cases like RegExp-patterns SQL-Statements etc.
These shouldn't be placed in resource files. At least, this is my
expierience.

Christof
May 9 '07 #13
On May 9, 3:47 pm, "Christof Nordiek" <c...@nospam.dewrote:
It all depends on what you're doing with it. If you're writing to the
console, then yes - but if you're getting the data ready to go down a
socket, then:
a) It makes sense to use a single string and encode it once
b) You need to make sure you use the appropriate line termination for
the protocol, rather than using Environment.NewLine.

So, what should I use ? MyProtocol.NewLine ? ;-)
Well, you could define a NewLine constant in an appropriate class,
certainly - that wouldn't be a bad idea. Specify it to be "\r\n" or
"\n" depending on the protocol.
It's certainly not the case that everywhere you see \n or \r\n you
should replace it with a call to Environment.NewLine.

But when shall one use it and when not?
Use Environment.NewLine when you want the current platform's default
line terminator, e.g. when writing text files for use on the local
machine. Use a specific line terminator in the cases where you know
for certain exactly which one you want to use.

Jon

May 9 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6731
by: Jan Burgy | last post by:
Hi everyone, can somebody tell me why (using Python 2.3.2) >>> import re >>> re.compile(r"^$", re.MULTILINE).split("foo\n\nbar\n\nbaz") ? Being used to Perl semantics, I expect
4
1544
by: Brent | last post by:
I'd like to think that my code* is pretty simple, but I'm running into memory errors when loading larger documents. The URL you see below in the first line of the Page_Load function is about 3...
4
6920
by: I_AM_DON_AND_YOU? | last post by:
A simple query: I have a textbox with multiline=true. Also there is a button1. In button1's click the code written is textbox1.lines(0) = "Microsoft" textbox2.lines(1) = "Visual Basic" ...
1
5646
by: Tomek | last post by:
Hi I use JGoodies Forms to create a GUI application. I need to show a simple multiline description in the window. I use JLabel with html text like "<HTML... my description ... </HTML>". ...
1
2307
by: gwillden | last post by:
Hello all, I'd like to propose the following change to ConfigParser.py. I won't call it a bug-fix because I don't know the relevant standards. This change will enable multiline comments as...
4
5997
by: giddy | last post by:
hi when i run this class i made here , this is what it looks like without text - http://gidsfiles.googlepages.com/LinedTextBox_1.jpg WITH TEXT (heres the issue) -...
19
3941
by: auratius | last post by:
http://www.auratius.co.za/CSharpCodingStandards.html Complete CSharp Coding Standards 1. Naming Conventions and Styles 2. Coding Practices 3. Project Settings and Project Structure 4....
2
3411
by: Mike | last post by:
I am trying to write a little program for my own use using VB2005 express edition. I have a list of peoples names in a file that I read into an array of strings. I am using a multiline textbox to...
2
2808
by: GS | last post by:
How can one avoid capturing leading empty or blank lines? the data I deal with look like this "will be paid on the dates you specified. xyz supplier amount: $100.52 when: September 07,...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.