Question

I'm trying to position a string at a certain starting position on a line, regardless of where the previous text ended. For instance:

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..

The explanation of the options begin at position 30 regardless of the text preceding. How do you accomplish this with java.util.Formatter? I have tested with both the width (%30s) and precision (%.30) arguments, and neither provide the desired result.

Was it helpful?

Solution

You can employ 'width' parameter, like this:

    System.out.println(String.format("%-30s%s", "  -a, --all", "do not ignore entries starting with ."));
    System.out.println(String.format("%-30s%s", "  -A, --almost-all", "do not list implied . and .."));

edit
Complete overview, if you're interested. It's not big at all, formatting functionality is quite limited.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top