开发者

Java Formatter specify starting position for text

开发者 https://www.devze.com 2023-01-02 10:15 出处:网络
I\'m trying to position a string at a certain starting position on a line, regardless of where the previous text ended. For instance:

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 (开发者_如何学Go%.30) arguments, and neither provide the desired result.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号