String verbatim
In this chapter you will learn:
Verbatim string literal
A verbatim string literal starts with @ and doesn't escape the chars. The following code rewrites the path in a verbatim string.
using System;//from j a va2 s . co m
class Program
{
static void Main(string[] args)
{
string path = @"c:\a\b\c\d.exe";
Console.WriteLine(path);
}
}
The output:
Quotation in verbatim string
To use double quotes in a verbatim string:
using System;//from j a v a 2 s.co m
class Program
{
static void Main(string[] args)
{
string str = @"This is a ""test"" from java2s.com";
Console.WriteLine(str);
}
}
The output:
multiple line string
using System; /* j av a 2s. c o m*/
class Example {
public static void Main() {
Console.WriteLine(@"BBBBBB
AAAAA
VVVVVVV
");
Console.WriteLine(@"Here is some tabbed output:
1 2 3 4
5 6 7 8
");
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » String