Inserting a " in a string

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

Guest

How can insert a " is a string ?

And Also

How can I insert a carriage return in a string ?
 
[C#]
string s = @"This is my "verbatim" string.";
string s = "This is my \"escaped\" string.";

[C#]
string s = "This is my string with a line break." + Environment.NewLine +
"Now I'm on a new line.";
Technically you could just use "\r\n" to indicate a new line. But the
Environment.NewLine property would be more robust in the sense that this
property returns a string based on the current platform. So if you, possibly
down the road, were running on a different platform then this would still
function properly. Plus, Environment.NewLine works in other languages were
"\r\n" is pretty much specific to the C language.

Is that what you were after?
 
* =?Utf-8?B?dmVkYW50XzE1?= said:
How can insert a " is a string ?

\\\
Dim s As String = "He said: ""Hello World""."
///
How can I insert a carriage return in a string ?

\\\
Dim s As String = "Hello" & ControlChars.Cr & "World"
///

For a new line, use 'ControlChars.NewLine' or 'Environment.NewLine'.
 
Sure. There's more than one way to do pretty much anything in .Net.

--
Tim Wilson
..Net Compact Framework MVP

Uri Dor said:
string BTW = @"this string includes
a newline";

Tim said:
[C#]
string s = @"This is my "verbatim" string.";
string s = "This is my \"escaped\" string.";

[C#]
string s = "This is my string with a line break." + Environment.NewLine +
"Now I'm on a new line.";
Technically you could just use "\r\n" to indicate a new line. But the
Environment.NewLine property would be more robust in the sense that this
property returns a string based on the current platform. So if you, possibly
down the road, were running on a different platform then this would still
function properly. Plus, Environment.NewLine works in other languages were
"\r\n" is pretty much specific to the C language.

Is that what you were after?
 
Back
Top