String verbatim

In this chapter you will learn:

  1. Verbatim string literal
  2. Quotation in verbatim string
  3. multiple line string

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:

  1. How to pad a string
  2. Pad with space
Home » C# Tutorial » String
string
String creation
Char in string
Compare strings
String equality
String concatanation
String copy
String Join
String split
String Search for Index
String contains
String start with
String insert
String case
Replacing substring
Remove from a string
Substring
Escape Characters
String verbatim
String padding
Switch on String
String trim
String intern
String normalization
Empty String