By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

Define a multiple line long string

P: n/a
Hi,

How can I define a long string variable in C# with multiple lines ?

For example

private string longName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
Feb 11 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Are you talking about concatenating them? You can always do this:

private string longName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";

The compiler will concatenate it at compile-time into one string.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<hu********@gmail.comwrote in message
news:61**********************************@i7g2000p rf.googlegroups.com...
Hi,

How can I define a long string variable in C# with multiple lines ?

For example

private string longName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";

Feb 11 '08 #2

P: n/a
Just stick a '+' at the end of the first line.

On Feb 12, 7:47 am, huohaod...@gmail.com wrote:
Hi,

How can I define a long string variable in C# with multiple lines ?

For example

private string longName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
Feb 11 '08 #3

P: n/a
hmm, if there is a long string, is there a double string (UTF-32/64?)
an signed string, maybe a booldean string? thsi is Zen at high level..
ah the boolena string is True/False, got 4-5 char in a bit...

;)

Just kidding...

//CY
Feb 11 '08 #4

P: n/a
ch*******@gmail.com skrev:
On 11 Feb, 22:47, huohaod...@gmail.com wrote:
>Hi,

How can I define a long string variable in C# with multiple lines ?

For example

private string longName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";

What is multiple lines? how long is a string as in a thread, the
physical piece of string I mean..

just "+" to concatenate, char 13/10 or is it 10/13 will break lines
when displaying them .. CR/LF maybe just CR (13) who knows... that up
to the receiver of the string...

\r \n are normally used for this...
Instead of guessing you can use Environment.NewLine

private string longName =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + Environment.NewLine +
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
>
--
Bjørn Brox
Feb 12 '08 #5

P: n/a
On Feb 12, 9:13 am, Bjørn Brox <bpb...@gmail.comwrote:

<snip>
Instead of guessing you can use Environment.NewLine

private string longName =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + Environment.NewLine +
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
And that's fine so long as you want it to use the platform default of
the operating system you're on - but there's more context than that.
Is it the same for an email body, for instance? How about telnet?

Environment.NewLine is a beguiling property because it leads to the
impression that you never need to worry about new lines again. That's
just untrue - you need to work out the context for your data, and what
the new line for that context is.

Jon
Feb 12 '08 #6

P: n/a
On 12 Feb, 10:17, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Feb 12, 9:13 am, Bjørn Brox <bpb...@gmail.comwrote:

<snip>
Instead of guessing you can use Environment.NewLine
private string longName =
* * *"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + Environment.NewLine +
* * *"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";

And that's fine so long as you want it to use the platform default of
the operating system you're on - but there's more context than that.
Is it the same for an email body, for instance? How about telnet?

Environment.NewLine is a beguiling property because it leads to the
impression that you never need to worry about new lines again. That's
just untrue - you need to work out the context for your data, and what
the new line for that context is.

Jon
[STX] yup, Im working with communications a bit, and what environment
im sitting on/in is not telling me what im communicating with is
accepting (yet anyways) [ETX]
that why the example, it wipes "dont" as you all realised, oh s*it
getting OT again... rereading the Q, the answer is + or @ as posted
earlyer by others...
//CY
Feb 12 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.