Define a multiple line long string

  • Thread starter Thread starter huohaodian
  • Start date Start date
H

huohaodian

Hi,

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

For example

private string longName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
 
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.
 
How can I define a long string variable in C# with multiple lines ?

For example

private string longName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";

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

(The concatenation is done at compile-time, not execution time.)

If you don't mind extra whitespace, you could use a verbatim string
literal:

private string longName = @"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
 
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...

like in

using System;
using System.Collections.Generic;
using System.Text;


namespace Test
{
class Slask
{
static void Main()
{

string slask = "dont\r" + "s" +
"a" + "y \n" +
"gobblebobble";

Console.WriteLine(slask);

Console.ReadKey();
}
}
}

;)

//CY
 
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
 
(e-mail address removed) skrev:
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";
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top