ascii code for a tab?

Discussion in 'Java' started by Ken Kafieh, May 10, 2004.

  1. Ken Kafieh

    Ken Kafieh Guest

    does anyone know the ascii code for a tab?
    Ken Kafieh, May 10, 2004
    #1
    1. Advertising

  2. Ken Kafieh wrote:

    > 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

    --
    Kind regards,
    Christophe Vanfleteren
    Christophe Vanfleteren, May 10, 2004
    #2
    1. Advertising

  3. Ken Kafieh wrote:

    > 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
    John C. Bollinger, May 10, 2004
    #3
  4. Ken Kafieh

    Roedy Green Guest

    Roedy Green, May 10, 2004
    #4
  5. Ken Kafieh

    Roedy Green Guest

    On Mon, 10 May 2004 13:17:08 GMT, Christophe Vanfleteren
    <> wrote or quoted :

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


    for more of those magic characters see
    http://mindprod.com/jgloss/literals.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, May 10, 2004
    #5
  6. Ken Kafieh

    Ken Kafieh Guest


    > 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.
    Ken Kafieh, May 10, 2004
    #6
  7. Ken Kafieh

    Tony Morris Guest

    > > 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
    Tony Morris, May 11, 2004
    #7
  8. Ken Kafieh

    Chris Smith Guest

    Tony Morris wrote:
    > 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
    Chris Smith, May 14, 2004
    #8
  9. Ken Kafieh

    Roedy Green Guest

    On Thu, 13 May 2004 17:13:51 -0600, Chris Smith <>
    wrote or quoted :

    >> System.out.println('\u0009');

    >
    >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.


    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, May 14, 2004
    #9
  10. Ken Kafieh

    Liz Guest

    "Chris Smith" <> wrote in message
    news:4.net...
    > Tony Morris wrote:
    > > 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!


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

    >
    > --
    > www.designacourse.com
    > The Easiest Way to Train Anyone... Anywhere.
    >
    > Chris Smith - Lead Software Developer/Technical Trainer
    > MindIQ Corporation
    Liz, May 14, 2004
    #10
  11. Ken Kafieh

    Tony Morris Guest

    > > // 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
    Tony Morris, May 15, 2004
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MadLucas
    Replies:
    2
    Views:
    70,446
    izmirl
    Oct 24, 2011
  2. TOXiC
    Replies:
    5
    Views:
    1,216
    TOXiC
    Jan 31, 2007
  3. James O'Brien
    Replies:
    3
    Views:
    231
    Ben Morrow
    Mar 5, 2004
  4. Alextophi
    Replies:
    8
    Views:
    481
    Alan J. Flavell
    Dec 30, 2005
  5. bruce
    Replies:
    38
    Views:
    255
    Mark Lawrence
    Nov 1, 2013
Loading...

Share This Page