views:

30

answers:

1

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.

+1  A: 

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

Nikita Rybak
@Nikita: thank you! Left-justifying the previous formatter is what I was looking for. I've read through the javadocs and the answer wasn't occurring to me.
purecharger