Simple Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Guys,

Just wondering how we can build up a string which needs to contain speech
mark symbols in the text itself. For example doing something like..

exampleString = "Join the "2" groups together"

I am not sure how to do that in C#. Currently I can only able to acheive
something like this as a short hand..

exampleString = "Join the '2' groups together"

by using single quotes which I do not need..

Looking for valuable feedback on this simple query.

Thanks.

Irfan
 
string example = "Join the \"2\" groups together";

or

string example = @"Join the ""2"" groups together";

bill
 
Hi Irfan,

The escape token in C# is the backslash ("\"). So, per your example:

exampleString = "Join the \"2\" groups together";

Another C# trick is to use the "@" token to indicate that the entire string
is escaped:

exampleString = @"Join the ""2"" groups together";

The "@ token indicates a "verbatim literal." This example may be a bit
confusing, as the only exception when creating a verbatim literal is the
double quote. When used with the verbatim literal, you escape the double
quote with another double quote.

Some other examples of verbatim literals, compared with their escaped
counterparts:

exampleString = "C:\\Temp\\SubTemp";
exampleString = @"C:\Temp\SubTemp";

exampleString = "Line One\r\nLine Two\r\nLine Three";
exampleString = @"Line one
Line Two
Line Three";

Note: There are several special escape sequences. Among these are \r
(Carriage Return Character) and \n (Line Feed Character).

You can read more (and save yourself a lot of future time waiting for
replies) by downloading and using the Microsoft .Net SDK:

http://www.microsoft.com/downloads/...A6-3647-4070-9F41-A333C6B9181D&displaylang=en

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.


--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
Back
Top