Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Wednesday 10 June 2015

STRING (ESCAPE SEQUENCES) IN C#


Today in Engineer's World, we are discussing a very important topic of C# -String in very easy way.


Click imaginationhunt.blogspot to see latest Blogs

7. To print newline
( \n ) is used to shift pointer to next line during run-time.

Practical Implementation:

using System;

namespace AspnetSolutions
{
    class stringEscapeSequences
    {
        public static void Main()
        {
            /*To print newline*/
            Console.WriteLine("newline = Imagination\nhunt");
        }
    }
}




Click imaginationhunt.blogspot to see latest Blogs 
As you can see that In the above example we want "imagination" and "hunt" to be written in two separate lines. And using (\n) we move the "hunt" printed in the next line.

8. To print carriage return 
( \r ) is a carriage return character, it tells your interpreter to move the cursor at the start of the line i.e.,  to the left side. The cursor is now at the position where the next characters will be rendered. So, printing a ( \r ) allows to override the current line interpreted.
 Practical Implementation:

using System;

namespace AspnetSolutions
{
    class stringEscapeSequences
    {
        public static void Main()
        {

            /*To print carriage return.*/
            Console.WriteLine("Carriage return = Imagination\rhunt");
        }
    }
}



The program is printing "Carriage return = Imagination", then it is moving the cursor back to the beginning of the line. And then it will print "hunt". It appears the beginning of the string is being overwritten as "huntiage return = Imagination".

9. To print horizontal tab
Horizontal Tab escape sequence ( \t ) is similar like pressing tab button from keyboard. It will make the cursor to give 3 or 4 spaces.
Practical Implementation:


Click imaginationhunt.blogspot to see latest Blogs

using System;

namespace AspnetSolutions
{
    class stringEscapeSequences
    {
        public static void Main()
        {
            /*To print horizontal tab*/
            Console.WriteLine("horizontal tab = Imagination\thunt\tblog\tspot");
        }
    }
}


To read STRING (ESCAPE SEQUENCES) IN C# Part 1 Blog - Click here

RELATED QUESTIONS



Q-1 Which of the following options are correct for an escape sequence?
A) r
B) \
C) b
D) $
Ans- Option (A, B and C).

Q-2 Which of the following are not correct escape sequences?
A) r, p, b, '
B) \, ", f, n
C) b, $, t, r
D) p, ?, \, n
Ans- Option (A, C, and D).
Explanation: Because p and $ are not an escape sequence.


Click imaginationhunt.blogspot to see latest Blogs 

Keep learning and sharing...

No comments:

Post a Comment

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...