View Full Version : What are these '\n' and '\t'
larswik
Oct 6, 2006, 10:54 PM
I hit page 200 in the Java for dummies book and when he talks about Switches the author start using code like this details += "\tNew Car Scent, Plus...\n";
He dosen't explaine it and it may not be important but it confuses me and I just wanted to understand it.
thanks.
-Lars
peterparker
Oct 6, 2006, 10:55 PM
\t = Tab
\n = New line
larswik
Oct 7, 2006, 12:48 AM
Ahhh, but they are located within the quates " " 's. My understanding is that everything that is located between them is printed "Print this statement";
-Lars
Eidorian
Oct 7, 2006, 12:50 AM
'\' is an escape character. The following character(s) are treated differently then printed text.
Heath
Oct 7, 2006, 12:53 AM
Ahhh, but they are located within the quates " " 's. My understanding is that everything that is located between them is printed "Print this statement";
-Lars
Yes, you are correct, everything in the quotes is printed. However there are things called 'escape sequences' these allow you to print characters you couldn't otherwise print in quotes. If you ponder a bit, how else could you print a double quote? Escape sequences are denoted by a \. So \n is the escape sequence for a new line and \t is the escape sequence for a tab. These are treated differently than normal text in the quotes. There are many escape sequences available your book probably covers them at some point, have a peek in the index.
hehe 3 minutes!
larswik
Oct 7, 2006, 11:56 AM
I understand now, thanks for the help.
-Lars
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.