Mark Puchala II
Mark Puchala II

Reputation: 652

\t spacing in notepad++'s nppexec

I've written a program in java "CircleDemo" that inevitably does this:

System.out.printf("The circle's area \t   is \t %.2f \n", circle.getArea());
System.out.printf("The circle's diameter \t   is \t %.2f \n", circle.getDiameter());
System.out.printf("The circle's circumference is \t %.2f \n", circle.getCircumference());

In cmd.exe the display looks like this:

The circle's area          is    3.14 
The circle's diameter      is    2.00
The circle's circumference is    6.28

Nice, clean formatting.

However, Notepad++'s console (nppexec) prints the same program like this:

The circle's area     is    3.14 
The circle's diameter      is    2.00
The circle's circumference is    6.28

You can see how the formatting is different. Now, I've played around long enough to find what's causing this is that "\t" prints tabs differently in cmd.exe vs Notepad++'s nppexec.

How could I edit nppexec's "\t" formatting to print "\t" the same as cmd.exe would?

Upvotes: 0

Views: 184

Answers (2)

Pshemo
Pshemo

Reputation: 124255

Avoid using \t to get array format. I would probably simply use

System.out.printf("The circle's area          is %.2f %n", circle.getArea() );
System.out.printf("The circle's diameter      is %.2f %n", circle.getDiameter());
System.out.printf("The circle's circumference is %.2f %n", circle.getCircumference());

If there is need to have more dynamic solution you could use

System.out.printf("The circle's %-13s is %.2f%n", "area", circle.getArea());

or if response doesn't need to always start with The circle's

System.out.printf("%-26s is %.2f%n", "The circle's area",  circle.getArea());

DEMO

Upvotes: 2

Olivier Poulin
Olivier Poulin

Reputation: 1796

You can try the below example. Do use '-' before the width to ensure left indentation. By default they will be right indented; which may not suit your purpose.

    System.out.printf("%-30s %-5s $%.2f\n","The circle's area ", "is" ,circle.getArea());
    System.out.printf("%-30s %-5s $%.2f\n","The circle's diameter ", "is" ,circle.getDiameter());
    System.out.printf("%-30s %-5s $%.2f\n","The circle's circumference ", "is" ,circle.getCircumference());

Source: http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax

Upvotes: 1

Related Questions