Constant String Concatenation

R

Reilly

To whomever cares at uSoft:

One feature that I'd like to see in C#, is the concatenation of
constant
quoted strings by the compiler, just like good 'ole C++:

string s = "Here is a string"
" that I'd like to line up,"
" just like C++";

Without the need for superfluous plus signs. And the continue on next
line business:

string s = @"Here is
a string over 2 lines";

is just a terrible idea! At least C had a backslash.

Otherwise, love it.

Thanks.

John Reilly
Sperry Marine
..NET Fan
 
J

Jon Skeet [C# MVP]

Reilly said:
To whomever cares at uSoft:

One feature that I'd like to see in C#, is the concatenation of
constant
quoted strings by the compiler, just like good 'ole C++:

string s = "Here is a string"
" that I'd like to line up,"
" just like C++";

Without the need for superfluous plus signs.

Why do the plus signs bother you so much? They make the language
cleaner IMO (no extra rules for two string literals in a row) and they
don't have any impact on the final code.
And the continue on next
line business:

string s = @"Here is
a string over 2 lines";

is just a terrible idea!

Well, it's not useful *terribly* often, but sometimes it can be
handy...
 
C

cody

One feature that I'd like to see in C#, is the concatenation of
constant
quoted strings by the compiler, just like good 'ole C++:

string s = "Here is a string"
" that I'd like to line up,"
" just like C++";

I'd suggest that

int age = 24;
string s = "Iam"age"years old.";

should be also possible then.
Without the need for superfluous plus signs. And the continue on next
line business:

string s = @"Here is
a string over 2 lines";

is just a terrible idea! At least C had a backslash.

I cannot imagine one situation where you would really need this.
If you have larger strings with special chars in it you read it from a
resource anyway.
The only reason is because M$ still sticks to its backslashes in paths to
stay incompatible with the rest of the universe. But generelly that is not
the problem because the WinAPI also accepts unixstyle-forwardslashes.
 
S

Stu Smith

Reilly said:
To whomever cares at uSoft:

One feature that I'd like to see in C#, is the concatenation of
constant
quoted strings by the compiler, just like good 'ole C++:

string s = "Here is a string"
" that I'd like to line up,"
" just like C++";

Without the need for superfluous plus signs. And the continue on next
line business:

string s = @"Here is
a string over 2 lines";

is just a terrible idea! At least C had a backslash.

I used to like the lcc-style underscore-pre-processor, so that

char *s = "This is a _
long string";

would be the same as:

char *s = "This is a long string";

but I think that's just nostalgia talking. I haven't written a multi-line
string constant for years.

Stu
 
E

Eric Gunnerson [MS]

As Jon points out, it's unlikely that we'd add a special rule for constant
strings just so the + signs could be omitted.

The multi-line constants are wonderful if you're writing complex regexes:

Regex regex = new Regex(@"
^ # anchor to start of string
\?[\<|'] # ?< or ?'
(?<Name1>[a-zA-Z]+?) # Capture name1
-
(?<Name2>[a-zA-Z]+?) # Capture name2
[\>|'] # ?> or ?'
(?<Rest>.+) # The rest of the expression
",
RegexOptions.IgnorePatternWhitespace);

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://weblogs.asp.net/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Top