Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday 9 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. Posted By- +Manish Kumar Gautam +LIVE VIAR +ASP.NET SOLUTIONS

Click imaginationhunt.blogspot to see latest Blogs

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

4. To initialize string as null
Initialize string to null (escape sequence).

Practical Implementation:

using System;

namespace AspnetSolutions
{
    class stringEscapeSequences
    {
        public static void Main()
        {
            /*Initializing string to null with escape sequence*/
            string str = "\0";
            Console.WriteLine("null by escape sequence = " + str);

            /*other ways to initialize string to null*/

            string a = null;
            Console.WriteLine("null by string variable a = " + a);
        }
    }
}




5. To print backspace
This escape sequence ( \b ) is used to remove one character from your string i.e, preceding to its left wherever it is mentioned.

Practical Implementation:

using System;

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


In our output 'n' is removed as ( \b ) is used just after "Imagination". Implies, that character i.e, preceding to left of ( \b ) is deleted.

6. To print Form feed
If you were programming for a 1980-style printer, it would eject the paper and start a new page. You are virtually certain to never need it. I have mentioned just in case to know what form feed escape sequence are.

Practical Implementation:

using System;

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

RELATED QUESTIONS:-


Q-1 Which of the following is not correct escape sequences?
A) r
B) \
C) b
D) $
Ans- Option (D).

Q-2 Which of the following are not correct escape sequences?
A) r, p, b, '
B) \, ", f, n
C) b, b, t, r
D) p, ?, \, n
Ans- Option (A and D).
Explanation: Because p is 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...