Sunday, August 23, 2015

Escape Character & Escape Sequence

Hi All...!

This post is about "escape character" and "Escape Sequence", Let's take a look at what is escape character,

escape character

 

Normally, the characters in a string are display exactly as they appear in the double quotes, when we use System.out's print and println methods. I think you have notice that when we use nextline character, "\n" didn't print on command window, that's because of this escape character in front of the newline command, escape character is "\" Backslash. If you use backslash the next character after the backslash will not display when you run your program. But you can't randomly use backslash to stop printing characters. If you use backslash randomly with out any knowledge you will get compilation error, that says "Illegal escape character".

Correct way to use escape character 

The correct way to use escape character is, use escape character with "Escape Sequence".

Following picture shows you list of a "Escape Sequence" used in Java.




In my next post I will show you how to use some common "Escape Sequence".

No comments:

Post a Comment