-->

Sunday, December 8, 2013

Computer programming : Print string in double quote escape sequences, Verbatim literal

Computer programming : Print string in double quote escape sequences, Verbatim literal

In c#, String is enclosed in double quote, suppose we want to store name then we should use string type. For example
String name="Computer Programming";

Starting double quote define the beginning of the string and ending double quote define the end of the string. Now if we want to print this string then in console application, we have to write:

System.Console.writeline (name);

If we want to print words Computer Programming in double quote or you can say output window display Computer Programming in double quote like "Computer Programming"

Note: If we use double quote beginning of the string like " "Computer Programming" then you get error in the string.

Solution: Use Escape sequence character (\) for keep double quote in the string.
For example :  String name = "\"Computer Programming\" ";
There are different types of escape sequences available in msdn library.

Lets take another example, if we want to print path of the file like C:\csharp\tutorial\beginning, then we  should use escape sequence character before every back slash.
Solution : C:\\csharp\\tutorial\\beginning.
Now this type of solution is too typical and unreadable string. So use verbatim literal for this
Solution : @” C:\csharp\tutorial\beginning”

Here @ symbol is a verbatim literal for removing escape sequences characters in the string.

Computer programming : Print string in double quote escape sequences, Verbatim literal

Here's the full program in c# language
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = "\"Computer Programming\"";
            Console.WriteLine(name);
            String path = @"C:\csharp\tutorial\beginning";
            Console.WriteLine(path);
            Console.ReadKey(false);
        }
    }
}

Write above lines of code in c# console application and run the project, string with quote and path with quote will display on the screen.



Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved