Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi all.

I am using Visual Studio 2010. Is there a way, while using Visual Studio 2010, that you can surround text spanning multiple lines with double quotes to mark it as a string? E.g.

My name

is Charles

and i am a programmer


instead of doing it manually by putting double quotes at the beginning and at the end and using '+' to join them?
Posted
Comments
[no name] 9-Sep-12 11:37am    
Why don't you use string.Format()?
Wamuti 9-Sep-12 11:47am    
That would be okay,but if i used .Format("",), i'd still have to flag string manually by using double quotes. :-)

You can add double quotes or other special characters by “escaping” them. For example:
C#
string escapedStr = "\"First line\nSecond line\"";

See this site[^] for a list of available escape characters.

As Mattias said you can simply prepend “@” to your string, however you need to be aware that it has some other effects; it causes escape characters to be treated as literals. See this article[^] for more details.
 
Share this answer
 
Comments
Kenneth Haugland 10-Sep-12 10:30am    
You cant use "@" in vb, so I guess It would help thouse guys anyway :)
BillW33 10-Sep-12 13:24pm    
That may be, but the OP's question is tagged for C# so it should work for him. :)
oh, yes. Like this.

const string mystr = @"
Hello
World";
 
Share this answer
 
v2
Comments
Wamuti 9-Sep-12 11:51am    
Hahaha. Thanks!!!! IT WORKED!!!!!!!!! I am so happy :-)
You can use something like this:

C#
string str = "First line.\nSecond line";


The \n char is the escape sequence for a new line.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900