ascii code for a tab?

C

Christophe Vanfleteren

Ken said:
does anyone know the ascii code for a tab?

If you need to print a tab:

System.out.println("This part goes before the \t, this part after it");

If you need the actual code: 9
 
J

John C. Bollinger

Ken said:
does anyone know the ascii code for a tab?

Have you tried looking it up in an ASCII table? You can only find about
a bazillion of them on the web. (Try
http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=ASCII+table&btnG=Google+Search)
Not to mention in the programmer's manuals of many compilers for many
languages. Or how about the empirical approach: even in Java, which
tends to be somewhat verbose when it comes to short programs, a console
program that would help you find the answer for yourself could be as
short as about a dozen lines. Any of those methods would have been
quicker than asking on Usenet.


John Bollinger
(e-mail address removed)
 
K

Ken Kafieh

Have you tried looking it up in an ASCII table? You can only find about
a bazillion of them on the web.

That didn't occur to me. It seems like a good idea now. But I never thought
of that as being something many people would necessarily display on the
Internet. There is so many more interesting things to put up. But now that
you mention it, it seems like better first step. I'll remember that for
next time.
Not to mention in the programmer's manuals of many compilers for many
languages.

I have no manual for the compiler or any compiler. I have no ascii tables at
my disposal. .
Or how about the empirical approach: even in Java, which tends to be
somewhat verbose when it comes to short programs, a console program that
would help you find the answer for yourself could be as short as about a
dozen lines.

I thought about that. I have done it before. but the program did so many
white space characters that I wasn't sure which one of them was the tab.
Any of those methods would have been quicker than asking on Usenet.

Thank you for helping me to improve my research skills. I am sorry for
bothering you.
 
T

Tony Morris

does anyone know the ascii code for a tab?
If you need to print a tab:

System.out.println("This part goes before the \t, this part after it");

If you need the actual code: 9


Note that you are printing a Unicode character representation, not ASCII.
Equivalent to:
System.out.println('\u0009');

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform
 
C

Chris Smith

Tony said:
Note that you are printing a Unicode character representation, not ASCII.
Equivalent to:
System.out.println('\u0009');

True, but perhaps a bit dangerous. It's sometimes important to know
that \uXXXX is a completely different construct in Java from \t. The
former is translated prior to lexical analysis, and is syntactically
significant; the latter form is interpreted after lexical and syntactic
analysis, and so can never affect the lexical structure or syntax of the
language.

For \t, this rarely matters except for the quibble that \t is only
allowed in a string literal, while \u0009 can occur anywhere in code.
However, try \u000A in a string literal and see what happens... or more
interestingly:

// This looks like \u000A it's all a comment, but it's not!

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roedy Green

True, but perhaps a bit dangerous.

it is treated exactly as if you had written
System.out.println (' ');
where you hit the tab character between the quotes.
Tab might work but NL would not. Because Java would look at that as:
System.out.println ('
');

Literals are not allowed to span lines.

You use \n.
 
L

Liz

Chris Smith said:
True, but perhaps a bit dangerous. It's sometimes important to know
that \uXXXX is a completely different construct in Java from \t. The
former is translated prior to lexical analysis, and is syntactically
significant; the latter form is interpreted after lexical and syntactic
analysis, and so can never affect the lexical structure or syntax of the
language.

For \t, this rarely matters except for the quibble that \t is only
allowed in a string literal, while \u0009 can occur anywhere in code.
However, try \u000A in a string literal and see what happens... or more
interestingly:

// This looks like \u000A it's all a comment, but it's not!

Now that is good to know,
I never would have thought of it, tnx.
 
T

Tony Morris

// This looks like \u000A it's all a comment, but it's not!
Now that is good to know,
I never would have thought of it, tnx.

Typical SCJP 1.2 exam question.
I haven't heard of such a thing in the 1.4 exam, and relevant study material
(and I certainly didn't get it in my exam).

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top