Search code examples
javaconsolenotepad++nppexec

\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?


Solution

  • 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